@shopify/react-native-skia 2.2.10 → 2.2.12
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/cpp/api/JsiNativeBuffer.h +2 -0
- package/cpp/api/JsiSkAnimatedImage.h +6 -2
- package/cpp/api/JsiSkAnimatedImageFactory.h +6 -3
- package/cpp/api/JsiSkApi.h +2 -0
- package/cpp/api/JsiSkCanvas.h +2 -0
- package/cpp/api/JsiSkColorFilter.h +2 -0
- package/cpp/api/JsiSkColorFilterFactory.h +31 -23
- package/cpp/api/JsiSkContourMeasure.h +8 -4
- package/cpp/api/JsiSkContourMeasureIter.h +10 -4
- package/cpp/api/JsiSkData.h +5 -0
- package/cpp/api/JsiSkDataFactory.h +14 -7
- package/cpp/api/JsiSkFont.h +17 -10
- package/cpp/api/JsiSkFontMgr.h +6 -2
- package/cpp/api/JsiSkFontMgrFactory.h +5 -2
- package/cpp/api/JsiSkFontStyle.h +6 -3
- package/cpp/api/JsiSkHostObjects.h +21 -44
- package/cpp/api/JsiSkImage.h +17 -8
- package/cpp/api/JsiSkImageFactory.h +26 -13
- package/cpp/api/JsiSkImageFilter.h +2 -0
- package/cpp/api/JsiSkImageFilterFactory.h +160 -143
- package/cpp/api/JsiSkImageInfo.h +6 -3
- package/cpp/api/JsiSkMaskFilter.h +2 -0
- package/cpp/api/JsiSkMaskFilterFactory.h +7 -5
- package/cpp/api/JsiSkMatrix.h +6 -2
- package/cpp/api/JsiSkPaint.h +9 -4
- package/cpp/api/JsiSkParagraph.h +26 -23
- package/cpp/api/JsiSkParagraphBuilder.h +6 -3
- package/cpp/api/JsiSkParagraphBuilderFactory.h +6 -3
- package/cpp/api/JsiSkPath.h +33 -15
- package/cpp/api/JsiSkPathEffect.h +2 -0
- package/cpp/api/JsiSkPathEffectFactory.h +37 -32
- package/cpp/api/JsiSkPathFactory.h +22 -10
- package/cpp/api/JsiSkPicture.h +13 -2
- package/cpp/api/JsiSkPictureFactory.h +6 -2
- package/cpp/api/JsiSkPictureRecorder.h +14 -6
- package/cpp/api/JsiSkPoint.h +9 -5
- package/cpp/api/JsiSkRRect.h +13 -8
- package/cpp/api/JsiSkRSXform.h +14 -8
- package/cpp/api/JsiSkRect.h +13 -8
- package/cpp/api/JsiSkRuntimeEffect.h +10 -6
- package/cpp/api/JsiSkRuntimeEffectFactory.h +6 -3
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +12 -6
- package/cpp/api/JsiSkSVG.h +24 -0
- package/cpp/api/JsiSkSVGFactory.h +8 -4
- package/cpp/api/JsiSkShader.h +2 -0
- package/cpp/api/JsiSkShaderFactory.h +34 -24
- package/cpp/api/JsiSkSkottie.h +29 -0
- package/cpp/api/JsiSkSurface.h +21 -5
- package/cpp/api/JsiSkSurfaceFactory.h +10 -6
- package/cpp/api/JsiSkTextBlob.h +12 -0
- package/cpp/api/JsiSkTextBlobFactory.h +18 -12
- package/cpp/api/JsiSkTypeface.h +19 -3
- package/cpp/api/JsiSkTypefaceFactory.h +6 -2
- package/cpp/api/JsiSkTypefaceFontProvider.h +10 -5
- package/cpp/api/JsiSkTypefaceFontProviderFactory.h +6 -3
- package/cpp/api/JsiSkVertices.h +16 -5
- package/cpp/api/JsiSkiaContext.h +10 -6
- package/cpp/api/JsiSkottieFactory.h +6 -3
- package/cpp/api/JsiVideo.h +10 -5
- package/cpp/api/recorder/DrawingCtx.h +2 -2
- package/cpp/api/recorder/JsiRecorder.h +12 -8
- package/cpp/api/recorder/Shaders.h +3 -2
- package/cpp/rnskia/RNSkJsiViewApi.h +22 -10
- package/lib/commonjs/renderer/Canvas.js +18 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +1 -1
- package/lib/commonjs/sksg/Container.js +2 -2
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.js +2 -5
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.d.ts +2 -3
- package/lib/commonjs/sksg/Container.web.js +7 -14
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/sksg/StaticContainer.d.ts +2 -4
- package/lib/commonjs/sksg/StaticContainer.js +1 -8
- package/lib/commonjs/sksg/StaticContainer.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.js +1 -0
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/renderer/Canvas.js +19 -2
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +1 -1
- package/lib/module/sksg/Container.js +2 -2
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Container.native.js +2 -5
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Container.web.d.ts +2 -3
- package/lib/module/sksg/Container.web.js +7 -14
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/sksg/StaticContainer.d.ts +2 -4
- package/lib/module/sksg/StaticContainer.js +1 -8
- package/lib/module/sksg/StaticContainer.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.js +1 -0
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/lib/commonjs/sksg/StaticContainer.d.ts +1 -2
- package/lib/typescript/lib/module/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/lib/module/sksg/StaticContainer.d.ts +1 -2
- package/lib/typescript/src/sksg/Container.d.ts +1 -1
- package/lib/typescript/src/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/src/sksg/StaticContainer.d.ts +2 -4
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +17 -0
- package/src/sksg/Container.native.ts +2 -9
- package/src/sksg/Container.ts +2 -2
- package/src/sksg/Container.web.ts +7 -25
- package/src/sksg/StaticContainer.ts +2 -17
- package/src/specs/NativeSkiaModule.web.ts +1 -0
package/cpp/api/JsiSkParagraph.h
CHANGED
@@ -95,46 +95,47 @@ public:
|
|
95
95
|
std::vector<para::LineMetrics> metrics;
|
96
96
|
getObject()->getLineMetrics(metrics);
|
97
97
|
auto returnValue = jsi::Array(runtime, metrics.size());
|
98
|
-
|
98
|
+
|
99
99
|
for (size_t i = 0; i < metrics.size(); ++i) {
|
100
100
|
auto lineMetrics = jsi::Object(runtime);
|
101
|
-
|
101
|
+
|
102
102
|
// Text indices
|
103
|
-
lineMetrics.setProperty(runtime, "startIndex",
|
103
|
+
lineMetrics.setProperty(runtime, "startIndex",
|
104
104
|
static_cast<double>(metrics[i].fStartIndex));
|
105
|
-
lineMetrics.setProperty(runtime, "endIndex",
|
105
|
+
lineMetrics.setProperty(runtime, "endIndex",
|
106
106
|
static_cast<double>(metrics[i].fEndIndex));
|
107
|
-
lineMetrics.setProperty(
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
lineMetrics.setProperty(
|
108
|
+
runtime, "endExcludingWhitespaces",
|
109
|
+
static_cast<double>(metrics[i].fEndExcludingWhitespaces));
|
110
|
+
lineMetrics.setProperty(
|
111
|
+
runtime, "endIncludingNewline",
|
112
|
+
static_cast<double>(metrics[i].fEndIncludingNewline));
|
113
|
+
|
112
114
|
// Line break info
|
113
|
-
lineMetrics.setProperty(runtime, "isHardBreak",
|
114
|
-
|
115
|
-
|
115
|
+
lineMetrics.setProperty(runtime, "isHardBreak", metrics[i].fHardBreak);
|
116
|
+
|
116
117
|
// Vertical metrics
|
117
|
-
lineMetrics.setProperty(runtime, "ascent",
|
118
|
+
lineMetrics.setProperty(runtime, "ascent",
|
118
119
|
static_cast<double>(metrics[i].fAscent));
|
119
|
-
lineMetrics.setProperty(runtime, "descent",
|
120
|
+
lineMetrics.setProperty(runtime, "descent",
|
120
121
|
static_cast<double>(metrics[i].fDescent));
|
121
|
-
lineMetrics.setProperty(runtime, "height",
|
122
|
+
lineMetrics.setProperty(runtime, "height",
|
122
123
|
static_cast<double>(metrics[i].fHeight));
|
123
|
-
|
124
|
+
|
124
125
|
// Horizontal metrics
|
125
|
-
lineMetrics.setProperty(runtime, "width",
|
126
|
+
lineMetrics.setProperty(runtime, "width",
|
126
127
|
static_cast<double>(metrics[i].fWidth));
|
127
|
-
lineMetrics.setProperty(runtime, "left",
|
128
|
+
lineMetrics.setProperty(runtime, "left",
|
128
129
|
static_cast<double>(metrics[i].fLeft));
|
129
|
-
|
130
|
+
|
130
131
|
// Position
|
131
|
-
lineMetrics.setProperty(runtime, "baseline",
|
132
|
+
lineMetrics.setProperty(runtime, "baseline",
|
132
133
|
static_cast<double>(metrics[i].fBaseline));
|
133
|
-
|
134
|
+
|
134
135
|
// Line number
|
135
|
-
lineMetrics.setProperty(runtime, "lineNumber",
|
136
|
+
lineMetrics.setProperty(runtime, "lineNumber",
|
136
137
|
static_cast<double>(metrics[i].fLineNumber));
|
137
|
-
|
138
|
+
|
138
139
|
returnValue.setValueAtIndex(runtime, i, lineMetrics);
|
139
140
|
}
|
140
141
|
return returnValue;
|
@@ -170,6 +171,8 @@ public:
|
|
170
171
|
JSI_EXPORT_FUNC(JsiSkParagraph, getLineMetrics),
|
171
172
|
JSI_EXPORT_FUNC(JsiSkParagraph, dispose))
|
172
173
|
|
174
|
+
size_t getMemoryPressure() const override { return 8192; }
|
175
|
+
|
173
176
|
explicit JsiSkParagraph(std::shared_ptr<RNSkPlatformContext> context,
|
174
177
|
para::ParagraphBuilder *paragraphBuilder)
|
175
178
|
: JsiSkWrappingSharedPtrHostObject<para::Paragraph>(
|
@@ -35,9 +35,10 @@ public:
|
|
35
35
|
JSI_API_TYPENAME("ParagraphBuilder");
|
36
36
|
|
37
37
|
JSI_HOST_FUNCTION(build) {
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
auto paragraph =
|
39
|
+
std::make_shared<JsiSkParagraph>(getContext(), _builder.get());
|
40
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, paragraph,
|
41
|
+
getContext());
|
41
42
|
}
|
42
43
|
|
43
44
|
JSI_HOST_FUNCTION(reset) {
|
@@ -109,6 +110,8 @@ public:
|
|
109
110
|
JSI_EXPORT_FUNC(JsiSkParagraphBuilder, pushStyle),
|
110
111
|
JSI_EXPORT_FUNC(JsiSkParagraphBuilder, pop))
|
111
112
|
|
113
|
+
size_t getMemoryPressure() const override { return 4096; }
|
114
|
+
|
112
115
|
explicit JsiSkParagraphBuilder(std::shared_ptr<RNSkPlatformContext> context,
|
113
116
|
para::ParagraphStyle paragraphStyle,
|
114
117
|
sk_sp<SkFontMgr> fontManager)
|
@@ -39,13 +39,16 @@ public:
|
|
39
39
|
: nullptr;
|
40
40
|
|
41
41
|
// Create the paragraph builder
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
auto builder = std::make_shared<JsiSkParagraphBuilder>(
|
43
|
+
getContext(), paragraphStyle, fontMgr);
|
44
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, builder,
|
45
|
+
getContext());
|
45
46
|
}
|
46
47
|
|
47
48
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkParagraphBuilderFactory, Make))
|
48
49
|
|
50
|
+
size_t getMemoryPressure() const override { return 3072; }
|
51
|
+
|
49
52
|
explicit JsiSkParagraphBuilderFactory(
|
50
53
|
std::shared_ptr<RNSkPlatformContext> context)
|
51
54
|
: JsiSkHostObject(std::move(context)) {}
|
package/cpp/api/JsiSkPath.h
CHANGED
@@ -173,15 +173,17 @@ public:
|
|
173
173
|
|
174
174
|
JSI_HOST_FUNCTION(computeTightBounds) {
|
175
175
|
auto result = getObject()->computeTightBounds();
|
176
|
-
|
177
|
-
|
176
|
+
auto hostObjectInstance = std::make_shared<JsiSkRect>(getContext(), result);
|
177
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
178
|
+
runtime, hostObjectInstance, getContext());
|
178
179
|
}
|
179
180
|
|
180
181
|
// TODO-API: Should this be a property?
|
181
182
|
JSI_HOST_FUNCTION(getBounds) {
|
182
183
|
auto result = getObject()->getBounds();
|
183
|
-
|
184
|
-
|
184
|
+
auto hostObjectInstance = std::make_shared<JsiSkRect>(getContext(), result);
|
185
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
186
|
+
runtime, hostObjectInstance, getContext());
|
185
187
|
}
|
186
188
|
|
187
189
|
JSI_HOST_FUNCTION(conicTo) {
|
@@ -330,8 +332,9 @@ public:
|
|
330
332
|
JSI_HOST_FUNCTION(getPoint) {
|
331
333
|
auto index = arguments[0].asNumber();
|
332
334
|
auto point = getObject()->getPoint(index);
|
333
|
-
|
334
|
-
|
335
|
+
auto hostObjectInstance = std::make_shared<JsiSkPoint>(getContext(), point);
|
336
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
337
|
+
runtime, hostObjectInstance, getContext());
|
335
338
|
}
|
336
339
|
|
337
340
|
JSI_HOST_FUNCTION(toSVGString) {
|
@@ -473,8 +476,10 @@ public:
|
|
473
476
|
|
474
477
|
JSI_HOST_FUNCTION(copy) {
|
475
478
|
const auto *path = getObject().get();
|
476
|
-
|
477
|
-
|
479
|
+
auto hostObjectInstance =
|
480
|
+
std::make_shared<JsiSkPath>(getContext(), SkPath(*path));
|
481
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
482
|
+
runtime, hostObjectInstance, getContext());
|
478
483
|
}
|
479
484
|
|
480
485
|
JSI_HOST_FUNCTION(op) {
|
@@ -509,8 +514,10 @@ public:
|
|
509
514
|
if (!succeed) {
|
510
515
|
return nullptr;
|
511
516
|
}
|
512
|
-
|
513
|
-
|
517
|
+
auto hostObjectInstance =
|
518
|
+
std::make_shared<JsiSkPath>(getContext(), std::move(result));
|
519
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
520
|
+
runtime, hostObjectInstance, getContext());
|
514
521
|
}
|
515
522
|
JSI_HOST_FUNCTION(toCmds) {
|
516
523
|
auto path = *getObject();
|
@@ -633,19 +640,30 @@ public:
|
|
633
640
|
: JsiSkWrappingSharedPtrHostObject<SkPath>(
|
634
641
|
std::move(context), std::make_shared<SkPath>(std::move(path))) {}
|
635
642
|
|
643
|
+
size_t getMemoryPressure() const override {
|
644
|
+
auto path = getObject();
|
645
|
+
if (!path)
|
646
|
+
return 0;
|
647
|
+
|
648
|
+
// SkPath provides approximateBytesUsed() to estimate memory usage
|
649
|
+
return path->approximateBytesUsed();
|
650
|
+
}
|
651
|
+
|
636
652
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
637
653
|
std::shared_ptr<RNSkPlatformContext> context,
|
638
654
|
const SkPath &path) {
|
639
|
-
|
640
|
-
|
655
|
+
auto hostObjectInstance = std::make_shared<JsiSkPath>(context, path);
|
656
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
657
|
+
runtime, hostObjectInstance, context);
|
641
658
|
}
|
642
659
|
|
643
660
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
644
661
|
std::shared_ptr<RNSkPlatformContext> context,
|
645
662
|
SkPath &&path) {
|
646
|
-
|
647
|
-
|
648
|
-
|
663
|
+
auto hostObjectInstance =
|
664
|
+
std::make_shared<JsiSkPath>(context, std::move(path));
|
665
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
666
|
+
runtime, hostObjectInstance, context);
|
649
667
|
}
|
650
668
|
};
|
651
669
|
|
@@ -25,6 +25,8 @@ public:
|
|
25
25
|
: JsiSkWrappingSkPtrHostObject<SkPathEffect>(std::move(context),
|
26
26
|
std::move(pathEffect)) {}
|
27
27
|
|
28
|
+
size_t getMemoryPressure() const override { return 2048; }
|
29
|
+
|
28
30
|
EXPORT_JSI_API_TYPENAME(JsiSkPathEffect, PathEffect)
|
29
31
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPathEffect, dispose))
|
30
32
|
};
|
@@ -29,9 +29,10 @@ class JsiSkPathEffectFactory : public JsiSkHostObject {
|
|
29
29
|
public:
|
30
30
|
JSI_HOST_FUNCTION(MakeCorner) {
|
31
31
|
int radius = arguments[0].asNumber();
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
33
|
+
getContext(), SkCornerPathEffect::Make(radius));
|
34
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
35
|
+
getContext());
|
35
36
|
}
|
36
37
|
|
37
38
|
JSI_HOST_FUNCTION(MakeDash) {
|
@@ -48,39 +49,40 @@ public:
|
|
48
49
|
? arguments[1].asNumber()
|
49
50
|
: 0;
|
50
51
|
auto i = SkSpan(intervals.data(), intervals.size());
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
53
|
+
getContext(), SkDashPathEffect::Make(i, phase));
|
54
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
55
|
+
getContext());
|
54
56
|
}
|
55
57
|
|
56
58
|
JSI_HOST_FUNCTION(MakeDiscrete) {
|
57
59
|
int segLength = arguments[0].asNumber();
|
58
60
|
int dec = arguments[1].asNumber();
|
59
61
|
int seedAssist = arguments[2].asNumber();
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
63
|
+
getContext(), SkDiscretePathEffect::Make(segLength, dec, seedAssist));
|
64
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
65
|
+
getContext());
|
64
66
|
}
|
65
67
|
|
66
68
|
JSI_HOST_FUNCTION(MakeCompose) {
|
67
69
|
auto outer = JsiSkPathEffect::fromValue(runtime, arguments[0]);
|
68
70
|
auto inner = JsiSkPathEffect::fromValue(runtime, arguments[1]);
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
72
|
+
getContext(),
|
73
|
+
SkPathEffect::MakeCompose(std::move(outer), std::move(inner)));
|
74
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
75
|
+
getContext());
|
74
76
|
}
|
75
77
|
|
76
78
|
JSI_HOST_FUNCTION(MakeSum) {
|
77
79
|
auto outer = JsiSkPathEffect::fromValue(runtime, arguments[0]);
|
78
80
|
auto inner = JsiSkPathEffect::fromValue(runtime, arguments[1]);
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
82
|
+
getContext(),
|
83
|
+
SkPathEffect::MakeSum(std::move(outer), std::move(inner)));
|
84
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
85
|
+
getContext());
|
84
86
|
}
|
85
87
|
|
86
88
|
JSI_HOST_FUNCTION(MakePath1D) {
|
@@ -89,27 +91,28 @@ public:
|
|
89
91
|
auto phase = arguments[2].asNumber();
|
90
92
|
auto style =
|
91
93
|
static_cast<SkPath1DPathEffect::Style>(arguments[3].asNumber());
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
95
|
+
getContext(), SkPath1DPathEffect::Make(*path, advance, phase, style));
|
96
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
97
|
+
getContext());
|
96
98
|
}
|
97
99
|
|
98
100
|
JSI_HOST_FUNCTION(MakePath2D) {
|
99
101
|
auto matrix = JsiSkMatrix::fromValue(runtime, arguments[0]);
|
100
102
|
auto path = JsiSkPath::fromValue(runtime, arguments[1]);
|
101
|
-
|
102
|
-
|
103
|
-
|
103
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
104
|
+
getContext(), SkPath2DPathEffect::Make(*matrix, *path));
|
105
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
106
|
+
getContext());
|
104
107
|
}
|
105
108
|
|
106
109
|
JSI_HOST_FUNCTION(MakeLine2D) {
|
107
110
|
auto width = arguments[0].asNumber();
|
108
111
|
auto matrix = JsiSkMatrix::fromValue(runtime, arguments[1]);
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
112
|
+
auto pathEffect = std::make_shared<JsiSkPathEffect>(
|
113
|
+
getContext(), SkLine2DPathEffect::Make(width, *matrix));
|
114
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pathEffect,
|
115
|
+
getContext());
|
113
116
|
}
|
114
117
|
|
115
118
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPathEffectFactory, MakeCorner),
|
@@ -119,7 +122,9 @@ public:
|
|
119
122
|
JSI_EXPORT_FUNC(JsiSkPathEffectFactory, MakeSum),
|
120
123
|
JSI_EXPORT_FUNC(JsiSkPathEffectFactory, MakeLine2D),
|
121
124
|
JSI_EXPORT_FUNC(JsiSkPathEffectFactory, MakePath1D),
|
122
|
-
JSI_EXPORT_FUNC(JsiSkPathEffectFactory, MakePath2D)
|
125
|
+
JSI_EXPORT_FUNC(JsiSkPathEffectFactory, MakePath2D))
|
126
|
+
|
127
|
+
size_t getMemoryPressure() const override { return 1024; }
|
123
128
|
|
124
129
|
explicit JsiSkPathEffectFactory(std::shared_ptr<RNSkPlatformContext> context)
|
125
130
|
: JsiSkHostObject(std::move(context)) {}
|
@@ -32,8 +32,10 @@ class JsiSkPathFactory : public JsiSkHostObject {
|
|
32
32
|
|
33
33
|
public:
|
34
34
|
JSI_HOST_FUNCTION(Make) {
|
35
|
-
|
36
|
-
|
35
|
+
auto hostObjectInstance =
|
36
|
+
std::make_shared<JsiSkPath>(getContext(), SkPath());
|
37
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
38
|
+
runtime, hostObjectInstance, getContext());
|
37
39
|
}
|
38
40
|
|
39
41
|
JSI_HOST_FUNCTION(MakeFromSVGString) {
|
@@ -45,8 +47,10 @@ public:
|
|
45
47
|
return jsi::Value(nullptr);
|
46
48
|
}
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
+
auto hostObjectInstance =
|
51
|
+
std::make_shared<JsiSkPath>(getContext(), std::move(result));
|
52
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
53
|
+
runtime, hostObjectInstance, getContext());
|
50
54
|
}
|
51
55
|
|
52
56
|
JSI_HOST_FUNCTION(MakeFromOp) {
|
@@ -58,8 +62,10 @@ public:
|
|
58
62
|
if (!success) {
|
59
63
|
return jsi::Value(nullptr);
|
60
64
|
}
|
61
|
-
|
62
|
-
|
65
|
+
auto hostObjectInstance =
|
66
|
+
std::make_shared<JsiSkPath>(getContext(), std::move(result));
|
67
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
68
|
+
runtime, hostObjectInstance, getContext());
|
63
69
|
}
|
64
70
|
|
65
71
|
JSI_HOST_FUNCTION(MakeFromCmds) {
|
@@ -144,8 +150,10 @@ public:
|
|
144
150
|
}
|
145
151
|
}
|
146
152
|
}
|
147
|
-
|
148
|
-
|
153
|
+
auto hostObjectInstance =
|
154
|
+
std::make_shared<JsiSkPath>(getContext(), std::move(path));
|
155
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
156
|
+
runtime, hostObjectInstance, getContext());
|
149
157
|
}
|
150
158
|
|
151
159
|
JSI_HOST_FUNCTION(MakeFromText) {
|
@@ -156,10 +164,14 @@ public:
|
|
156
164
|
SkPath path;
|
157
165
|
SkTextUtils::GetPath(text.c_str(), strlen(text.c_str()),
|
158
166
|
SkTextEncoding::kUTF8, x, y, *font, &path);
|
159
|
-
|
160
|
-
|
167
|
+
auto hostObjectInstance =
|
168
|
+
std::make_shared<JsiSkPath>(getContext(), std::move(path));
|
169
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
170
|
+
runtime, hostObjectInstance, getContext());
|
161
171
|
}
|
162
172
|
|
173
|
+
size_t getMemoryPressure() const override { return 1024; }
|
174
|
+
|
163
175
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPathFactory, Make),
|
164
176
|
JSI_EXPORT_FUNC(JsiSkPathFactory, MakeFromSVGString),
|
165
177
|
JSI_EXPORT_FUNC(JsiSkPathFactory, MakeFromOp),
|
package/cpp/api/JsiSkPicture.h
CHANGED
@@ -39,8 +39,9 @@ public:
|
|
39
39
|
|
40
40
|
// Create shader
|
41
41
|
auto shader = getObject()->makeShader(tmx, tmy, fm, m, tr);
|
42
|
-
|
43
|
-
|
42
|
+
auto shaderObj = std::make_shared<JsiSkShader>(getContext(), shader);
|
43
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shaderObj,
|
44
|
+
getContext());
|
44
45
|
}
|
45
46
|
|
46
47
|
JSI_HOST_FUNCTION(serialize) {
|
@@ -67,5 +68,15 @@ public:
|
|
67
68
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPicture, makeShader),
|
68
69
|
JSI_EXPORT_FUNC(JsiSkPicture, serialize),
|
69
70
|
JSI_EXPORT_FUNC(JsiSkPicture, dispose))
|
71
|
+
|
72
|
+
size_t getMemoryPressure() const override {
|
73
|
+
auto picture = getObject();
|
74
|
+
if (!picture) {
|
75
|
+
return 0;
|
76
|
+
}
|
77
|
+
// SkPicture provides approximateBytesUsed() method to estimate memory usage
|
78
|
+
auto bytesUsed = picture->approximateBytesUsed();
|
79
|
+
return bytesUsed;
|
80
|
+
}
|
70
81
|
};
|
71
82
|
} // namespace RNSkia
|
@@ -35,8 +35,10 @@ public:
|
|
35
35
|
SkData::MakeWithCopy(buffer.data(runtime), buffer.size(runtime));
|
36
36
|
auto picture = SkPicture::MakeFromData(data.get());
|
37
37
|
if (picture != nullptr) {
|
38
|
-
|
39
|
-
|
38
|
+
auto hostObjectInstance =
|
39
|
+
std::make_shared<JsiSkPicture>(getContext(), std::move(picture));
|
40
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
41
|
+
runtime, hostObjectInstance, getContext());
|
40
42
|
} else {
|
41
43
|
return jsi::Value::undefined();
|
42
44
|
}
|
@@ -44,6 +46,8 @@ public:
|
|
44
46
|
|
45
47
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPictureFactory, MakePicture))
|
46
48
|
|
49
|
+
size_t getMemoryPressure() const override { return 1024; }
|
50
|
+
|
47
51
|
explicit JsiSkPictureFactory(std::shared_ptr<RNSkPlatformContext> context)
|
48
52
|
: JsiSkHostObject(std::move(context)) {}
|
49
53
|
};
|
@@ -37,14 +37,17 @@ public:
|
|
37
37
|
SkRect rect = SkRect::Make(size);
|
38
38
|
canvas = getObject()->beginRecording(rect, nullptr);
|
39
39
|
}
|
40
|
-
|
41
|
-
|
40
|
+
auto canvasObj = std::make_shared<JsiSkCanvas>(getContext(), canvas);
|
41
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, canvasObj,
|
42
|
+
getContext());
|
42
43
|
}
|
43
44
|
|
44
45
|
JSI_HOST_FUNCTION(finishRecordingAsPicture) {
|
45
46
|
auto picture = getObject()->finishRecordingAsPicture();
|
46
|
-
|
47
|
-
|
47
|
+
auto hostObjectInstance =
|
48
|
+
std::make_shared<JsiSkPicture>(getContext(), std::move(picture));
|
49
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
50
|
+
runtime, hostObjectInstance, getContext());
|
48
51
|
}
|
49
52
|
|
50
53
|
EXPORT_JSI_API_TYPENAME(JsiSkPictureRecorder, PictureRecorder)
|
@@ -54,11 +57,16 @@ public:
|
|
54
57
|
finishRecordingAsPicture),
|
55
58
|
JSI_EXPORT_FUNC(JsiSkPictureRecorder, dispose))
|
56
59
|
|
60
|
+
size_t getMemoryPressure() const override {
|
61
|
+
return sizeof(SkPictureRecorder);
|
62
|
+
}
|
63
|
+
|
57
64
|
static const jsi::HostFunctionType
|
58
65
|
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
59
66
|
return JSI_HOST_FUNCTION_LAMBDA {
|
60
|
-
|
61
|
-
|
67
|
+
auto recorder = std::make_shared<JsiSkPictureRecorder>(context);
|
68
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, recorder,
|
69
|
+
context);
|
62
70
|
};
|
63
71
|
}
|
64
72
|
};
|
package/cpp/api/JsiSkPoint.h
CHANGED
@@ -57,10 +57,13 @@ public:
|
|
57
57
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
58
58
|
std::shared_ptr<RNSkPlatformContext> context,
|
59
59
|
const SkPoint &point) {
|
60
|
-
|
61
|
-
|
60
|
+
auto pointObj = std::make_shared<JsiSkPoint>(std::move(context), point);
|
61
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pointObj,
|
62
|
+
context);
|
62
63
|
}
|
63
64
|
|
65
|
+
size_t getMemoryPressure() const override { return sizeof(SkPoint); }
|
66
|
+
|
64
67
|
/**
|
65
68
|
* Creates the function for construction a new instance of the SkPoint
|
66
69
|
* wrapper
|
@@ -75,9 +78,10 @@ public:
|
|
75
78
|
SkPoint::Make(arguments[0].asNumber(), arguments[1].asNumber());
|
76
79
|
|
77
80
|
// Return the newly constructed object
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
auto pointObj =
|
82
|
+
std::make_shared<JsiSkPoint>(std::move(context), std::move(point));
|
83
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, pointObj,
|
84
|
+
context);
|
81
85
|
};
|
82
86
|
}
|
83
87
|
};
|
package/cpp/api/JsiSkRRect.h
CHANGED
@@ -30,9 +30,10 @@ public:
|
|
30
30
|
return static_cast<double>(getObject()->getSimpleRadii().y());
|
31
31
|
}
|
32
32
|
JSI_PROPERTY_GET(rect) {
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
auto rectObj =
|
34
|
+
std::make_shared<JsiSkRect>(getContext(), getObject()->getBounds());
|
35
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, rectObj,
|
36
|
+
getContext());
|
36
37
|
}
|
37
38
|
|
38
39
|
JSI_API_TYPENAME("RRect");
|
@@ -100,10 +101,13 @@ public:
|
|
100
101
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
101
102
|
std::shared_ptr<RNSkPlatformContext> context,
|
102
103
|
const SkRRect &rect) {
|
103
|
-
|
104
|
-
|
104
|
+
auto rrectObj = std::make_shared<JsiSkRRect>(std::move(context), rect);
|
105
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, rrectObj,
|
106
|
+
context);
|
105
107
|
}
|
106
108
|
|
109
|
+
size_t getMemoryPressure() const override { return sizeof(SkRRect); }
|
110
|
+
|
107
111
|
/**
|
108
112
|
* Creates the function for construction a new instance of the SkRect
|
109
113
|
* wrapper
|
@@ -120,9 +124,10 @@ public:
|
|
120
124
|
auto ry = arguments[2].asNumber();
|
121
125
|
auto rrect = SkRRect::MakeRectXY(*rect, rx, ry);
|
122
126
|
// Return the newly constructed object
|
123
|
-
|
124
|
-
|
125
|
-
|
127
|
+
auto rrectObj =
|
128
|
+
std::make_shared<JsiSkRRect>(std::move(context), std::move(rrect));
|
129
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, rrectObj,
|
130
|
+
context);
|
126
131
|
};
|
127
132
|
}
|
128
133
|
};
|
package/cpp/api/JsiSkRSXform.h
CHANGED
@@ -84,8 +84,10 @@ public:
|
|
84
84
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
85
85
|
std::shared_ptr<RNSkPlatformContext> context,
|
86
86
|
const SkRSXform &rsxform) {
|
87
|
-
|
88
|
-
|
87
|
+
auto rsxformObj =
|
88
|
+
std::make_shared<JsiSkRSXform>(std::move(context), rsxform);
|
89
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, rsxformObj,
|
90
|
+
context);
|
89
91
|
}
|
90
92
|
|
91
93
|
/**
|
@@ -103,11 +105,14 @@ public:
|
|
103
105
|
arguments[2].asNumber(), arguments[3].asNumber(),
|
104
106
|
arguments[4].asNumber(), arguments[5].asNumber());
|
105
107
|
// Return the newly constructed object
|
106
|
-
|
107
|
-
|
108
|
-
|
108
|
+
auto rsxformObj = std::make_shared<JsiSkRSXform>(std::move(context),
|
109
|
+
std::move(rsxform));
|
110
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, rsxformObj,
|
111
|
+
context);
|
109
112
|
};
|
110
113
|
}
|
114
|
+
size_t getMemoryPressure() const override { return sizeof(SkRSXform); }
|
115
|
+
|
111
116
|
/**
|
112
117
|
* Creates the function for construction a new instance of the SkRSXform
|
113
118
|
* wrapper
|
@@ -122,9 +127,10 @@ public:
|
|
122
127
|
SkRSXform::Make(arguments[0].asNumber(), arguments[1].asNumber(),
|
123
128
|
arguments[2].asNumber(), arguments[3].asNumber());
|
124
129
|
// Return the newly constructed object
|
125
|
-
|
126
|
-
|
127
|
-
|
130
|
+
auto rsxformObj = std::make_shared<JsiSkRSXform>(std::move(context),
|
131
|
+
std::move(rsxform));
|
132
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, rsxformObj,
|
133
|
+
context);
|
128
134
|
};
|
129
135
|
}
|
130
136
|
};
|