@shopify/react-native-skia 2.2.11 → 2.2.13
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 +2 -0
- 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/JsiRecorder.h +9 -4
- package/cpp/jsi/JsiHostObject.h +3 -3
- package/cpp/rnskia/RNSkJsiViewApi.h +10 -2
- package/package.json +1 -1
@@ -56,9 +56,14 @@ public:
|
|
56
56
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
57
57
|
std::shared_ptr<RNSkPlatformContext> context,
|
58
58
|
const SkRuntimeShaderBuilder &rt) {
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
auto builder =
|
60
|
+
std::make_shared<JsiSkRuntimeShaderBuilder>(std::move(context), rt);
|
61
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, builder,
|
62
|
+
context);
|
63
|
+
}
|
64
|
+
|
65
|
+
size_t getMemoryPressure() const override {
|
66
|
+
return sizeof(SkRuntimeShaderBuilder);
|
62
67
|
}
|
63
68
|
|
64
69
|
/**
|
@@ -74,9 +79,10 @@ public:
|
|
74
79
|
auto rt = JsiSkRuntimeEffect::fromValue(runtime, arguments[0]);
|
75
80
|
auto rtb = SkRuntimeShaderBuilder(rt);
|
76
81
|
// Return the newly constructed object
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
auto builder = std::make_shared<JsiSkRuntimeShaderBuilder>(
|
83
|
+
std::move(context), std::move(rtb));
|
84
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, builder,
|
85
|
+
context);
|
80
86
|
};
|
81
87
|
}
|
82
88
|
};
|
package/cpp/api/JsiSkSVG.h
CHANGED
@@ -45,6 +45,30 @@ public:
|
|
45
45
|
const jsi::Value &obj) {
|
46
46
|
return obj.asObject(runtime).asHostObject<JsiSkSVG>(runtime)->getObject();
|
47
47
|
}
|
48
|
+
|
49
|
+
size_t getMemoryPressure() const override {
|
50
|
+
auto svgdom = getObject();
|
51
|
+
if (!svgdom) {
|
52
|
+
return 1024; // Base size if no SVG
|
53
|
+
}
|
54
|
+
|
55
|
+
auto containerSize = svgdom->containerSize();
|
56
|
+
|
57
|
+
// Estimate memory usage based on SVG dimensions
|
58
|
+
// SVG rendering typically requires:
|
59
|
+
// - Vector data storage (base overhead)
|
60
|
+
// - Potential rasterization buffer (width * height * 4 bytes per pixel)
|
61
|
+
size_t rasterBufferSize =
|
62
|
+
static_cast<size_t>(containerSize.width() * containerSize.height() * 4);
|
63
|
+
|
64
|
+
// Add base overhead for SVG DOM structure, paths, and vector data
|
65
|
+
size_t baseOverhead = 32 * 1024; // 32KB for SVG DOM, paths, styles, etc.
|
66
|
+
|
67
|
+
// SVGs are typically lighter than raster images but heavier than simple
|
68
|
+
// vectors Use a fraction of full raster size plus base overhead
|
69
|
+
return (rasterBufferSize / 4) +
|
70
|
+
baseOverhead; // Quarter of full raster + overhead
|
71
|
+
}
|
48
72
|
};
|
49
73
|
|
50
74
|
} // namespace RNSkia
|
@@ -27,18 +27,22 @@ public:
|
|
27
27
|
auto data = JsiSkData::fromValue(runtime, arguments[0]);
|
28
28
|
auto stream = SkMemoryStream::Make(data);
|
29
29
|
auto svg_dom = SkSVGDOM::Builder().make(*stream);
|
30
|
-
|
31
|
-
|
30
|
+
auto svg = std::make_shared<JsiSkSVG>(getContext(), std::move(svg_dom));
|
31
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, svg,
|
32
|
+
getContext());
|
32
33
|
}
|
33
34
|
|
34
35
|
JSI_HOST_FUNCTION(MakeFromString) {
|
35
36
|
auto svgText = arguments[0].asString(runtime).utf8(runtime);
|
36
37
|
auto stream = SkMemoryStream::MakeDirect(svgText.c_str(), svgText.size());
|
37
38
|
auto svg_dom = SkSVGDOM::Builder().make(*stream);
|
38
|
-
|
39
|
-
|
39
|
+
auto svg = std::make_shared<JsiSkSVG>(getContext(), std::move(svg_dom));
|
40
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, svg,
|
41
|
+
getContext());
|
40
42
|
}
|
41
43
|
|
44
|
+
size_t getMemoryPressure() const override { return 512; }
|
45
|
+
|
42
46
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSVGFactory, MakeFromData),
|
43
47
|
JSI_EXPORT_FUNC(JsiSkSVGFactory, MakeFromString))
|
44
48
|
|
package/cpp/api/JsiSkShader.h
CHANGED
@@ -26,6 +26,8 @@ public:
|
|
26
26
|
: JsiSkWrappingSkPtrHostObject<SkShader>(std::move(context),
|
27
27
|
std::move(shader)) {}
|
28
28
|
|
29
|
+
size_t getMemoryPressure() const override { return 4096; }
|
30
|
+
|
29
31
|
EXPORT_JSI_API_TYPENAME(JsiSkShader, Shader)
|
30
32
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkShader, dispose))
|
31
33
|
};
|
@@ -100,9 +100,10 @@ public:
|
|
100
100
|
sk_sp<SkShader> gradient = SkGradientShader::MakeLinear(
|
101
101
|
pts, colors.data(), !positions.empty() ? positions.data() : nullptr,
|
102
102
|
static_cast<int>(colorsSize), tileMode, flag, localMatrix);
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
auto shader =
|
104
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
105
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
106
|
+
getContext());
|
106
107
|
}
|
107
108
|
|
108
109
|
JSI_HOST_FUNCTION(MakeRadialGradient) {
|
@@ -128,9 +129,10 @@ public:
|
|
128
129
|
center, r, colors.data(),
|
129
130
|
!positions.empty() ? positions.data() : nullptr,
|
130
131
|
static_cast<int>(colorsSize), tileMode, flag, localMatrix);
|
131
|
-
|
132
|
-
|
133
|
-
|
132
|
+
auto shader =
|
133
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
134
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
135
|
+
getContext());
|
134
136
|
}
|
135
137
|
|
136
138
|
JSI_HOST_FUNCTION(MakeSweepGradient) {
|
@@ -158,9 +160,10 @@ public:
|
|
158
160
|
x, y, colors.data(), !positions.empty() ? positions.data() : nullptr,
|
159
161
|
static_cast<int>(colorsSize), tileMode, startAngle, endAngle, flag,
|
160
162
|
localMatrix);
|
161
|
-
|
162
|
-
|
163
|
-
|
163
|
+
auto shader =
|
164
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
165
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
166
|
+
getContext());
|
164
167
|
}
|
165
168
|
|
166
169
|
JSI_HOST_FUNCTION(MakeTwoPointConicalGradient) {
|
@@ -191,9 +194,10 @@ public:
|
|
191
194
|
!positions.empty() ? positions.data() : nullptr,
|
192
195
|
static_cast<int>(colorsSize), tileMode, flag, localMatrix);
|
193
196
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
+
auto shader =
|
198
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
199
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
200
|
+
getContext());
|
197
201
|
}
|
198
202
|
|
199
203
|
JSI_HOST_FUNCTION(MakeTurbulence) {
|
@@ -206,9 +210,10 @@ public:
|
|
206
210
|
SkISize size = SkISize::Make(tileW, tileH);
|
207
211
|
sk_sp<SkShader> gradient =
|
208
212
|
SkShaders::MakeTurbulence(baseFreqX, baseFreqY, octaves, seed, &size);
|
209
|
-
|
210
|
-
|
211
|
-
|
213
|
+
auto shader =
|
214
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
215
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
216
|
+
getContext());
|
212
217
|
}
|
213
218
|
|
214
219
|
JSI_HOST_FUNCTION(MakeFractalNoise) {
|
@@ -221,9 +226,10 @@ public:
|
|
221
226
|
SkISize size = SkISize::Make(tileW, tileH);
|
222
227
|
sk_sp<SkShader> gradient =
|
223
228
|
SkShaders::MakeFractalNoise(baseFreqX, baseFreqY, octaves, seed, &size);
|
224
|
-
|
225
|
-
|
226
|
-
|
229
|
+
auto shader =
|
230
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
231
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
232
|
+
getContext());
|
227
233
|
}
|
228
234
|
|
229
235
|
JSI_HOST_FUNCTION(MakeBlend) {
|
@@ -231,19 +237,23 @@ public:
|
|
231
237
|
auto one = JsiSkShader::fromValue(runtime, arguments[1]);
|
232
238
|
auto two = JsiSkShader::fromValue(runtime, arguments[2]);
|
233
239
|
sk_sp<SkShader> gradient = SkShaders::Blend(blendMode, one, two);
|
234
|
-
|
235
|
-
|
236
|
-
|
240
|
+
auto shader =
|
241
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
242
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
243
|
+
getContext());
|
237
244
|
}
|
238
245
|
|
239
246
|
JSI_HOST_FUNCTION(MakeColor) {
|
240
247
|
auto color = JsiSkColor::fromValue(runtime, arguments[0]);
|
241
248
|
sk_sp<SkShader> gradient = SkShaders::Color(color);
|
242
|
-
|
243
|
-
|
244
|
-
|
249
|
+
auto shader =
|
250
|
+
std::make_shared<JsiSkShader>(getContext(), std::move(gradient));
|
251
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, shader,
|
252
|
+
getContext());
|
245
253
|
}
|
246
254
|
|
255
|
+
size_t getMemoryPressure() const override { return 1024; }
|
256
|
+
|
247
257
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkShaderFactory, MakeLinearGradient),
|
248
258
|
JSI_EXPORT_FUNC(JsiSkShaderFactory, MakeRadialGradient),
|
249
259
|
JSI_EXPORT_FUNC(JsiSkShaderFactory, MakeSweepGradient),
|
package/cpp/api/JsiSkSkottie.h
CHANGED
@@ -586,5 +586,34 @@ public:
|
|
586
586
|
std::shared_ptr<ManagedAnimation> animation)
|
587
587
|
: JsiSkWrappingSharedPtrHostObject<ManagedAnimation>(
|
588
588
|
std::move(context), std::move(animation)) {}
|
589
|
+
|
590
|
+
size_t getMemoryPressure() const override {
|
591
|
+
auto animation = getObject();
|
592
|
+
if (!animation || !animation->_animation) {
|
593
|
+
return 1024; // Base size if no animation
|
594
|
+
}
|
595
|
+
|
596
|
+
auto size = animation->_animation->size();
|
597
|
+
auto duration = animation->_animation->duration();
|
598
|
+
auto fps = animation->_animation->fps();
|
599
|
+
|
600
|
+
// Estimate memory usage based on animation properties
|
601
|
+
// Base calculation: width * height * 4 bytes per pixel * estimated frame
|
602
|
+
// count
|
603
|
+
size_t frameCount = static_cast<size_t>(duration * fps);
|
604
|
+
size_t estimatedFrameSize =
|
605
|
+
static_cast<size_t>(size.width() * size.height() * 4);
|
606
|
+
|
607
|
+
// Conservative estimate: assume some frames are cached
|
608
|
+
size_t cachedFrames =
|
609
|
+
std::min(frameCount, static_cast<size_t>(60)); // Max 60 cached frames
|
610
|
+
size_t animationMemory = estimatedFrameSize * cachedFrames;
|
611
|
+
|
612
|
+
// Add base overhead for animation data structures
|
613
|
+
size_t baseOverhead =
|
614
|
+
64 * 1024; // 64KB for metadata, property managers, etc.
|
615
|
+
|
616
|
+
return animationMemory + baseOverhead;
|
617
|
+
}
|
589
618
|
};
|
590
619
|
} // namespace RNSkia
|
package/cpp/api/JsiSkSurface.h
CHANGED
@@ -43,9 +43,10 @@ public:
|
|
43
43
|
}
|
44
44
|
|
45
45
|
JSI_HOST_FUNCTION(getCanvas) {
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
auto canvas =
|
47
|
+
std::make_shared<JsiSkCanvas>(getContext(), getObject()->getCanvas());
|
48
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, canvas,
|
49
|
+
getContext());
|
49
50
|
}
|
50
51
|
|
51
52
|
JSI_HOST_FUNCTION(flush) {
|
@@ -81,8 +82,10 @@ public:
|
|
81
82
|
jsiImage->setObject(image);
|
82
83
|
return jsi::Value(runtime, arguments[1]);
|
83
84
|
}
|
84
|
-
|
85
|
-
|
85
|
+
auto hostObjectInstance =
|
86
|
+
std::make_shared<JsiSkImage>(getContext(), std::move(image));
|
87
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
88
|
+
runtime, hostObjectInstance, getContext());
|
86
89
|
}
|
87
90
|
|
88
91
|
JSI_HOST_FUNCTION(getNativeTextureUnstable) {
|
@@ -90,6 +93,19 @@ public:
|
|
90
93
|
return JsiTextureInfo::toValue(runtime, texInfo);
|
91
94
|
}
|
92
95
|
|
96
|
+
size_t getMemoryPressure() const override {
|
97
|
+
auto surface = getObject();
|
98
|
+
if (!surface)
|
99
|
+
return 0;
|
100
|
+
|
101
|
+
// Surface memory is primarily the pixel buffer: width × height × bytes per
|
102
|
+
// pixel
|
103
|
+
int width = surface->width();
|
104
|
+
int height = surface->height();
|
105
|
+
// Assume 4 bytes per pixel (RGBA) for most surfaces
|
106
|
+
return width * height * 4;
|
107
|
+
}
|
108
|
+
|
93
109
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurface, width),
|
94
110
|
JSI_EXPORT_FUNC(JsiSkSurface, height),
|
95
111
|
JSI_EXPORT_FUNC(JsiSkSurface, getCanvas),
|
@@ -30,9 +30,10 @@ public:
|
|
30
30
|
if (surface == nullptr) {
|
31
31
|
return jsi::Value::null();
|
32
32
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
auto hostObjectInstance =
|
34
|
+
std::make_shared<JsiSkSurface>(getContext(), std::move(surface));
|
35
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
36
|
+
runtime, hostObjectInstance, getContext());
|
36
37
|
}
|
37
38
|
|
38
39
|
JSI_HOST_FUNCTION(MakeOffscreen) {
|
@@ -43,14 +44,17 @@ public:
|
|
43
44
|
if (surface == nullptr) {
|
44
45
|
return jsi::Value::null();
|
45
46
|
}
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
auto hostObjectInstance =
|
48
|
+
std::make_shared<JsiSkSurface>(getContext(), std::move(surface));
|
49
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
50
|
+
runtime, hostObjectInstance, getContext());
|
49
51
|
}
|
50
52
|
|
51
53
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make),
|
52
54
|
JSI_EXPORT_FUNC(JsiSkSurfaceFactory, MakeOffscreen))
|
53
55
|
|
56
|
+
size_t getMemoryPressure() const override { return 2048; }
|
57
|
+
|
54
58
|
explicit JsiSkSurfaceFactory(std::shared_ptr<RNSkPlatformContext> context)
|
55
59
|
: JsiSkHostObject(std::move(context)) {}
|
56
60
|
};
|
package/cpp/api/JsiSkTextBlob.h
CHANGED
@@ -25,6 +25,18 @@ public:
|
|
25
25
|
: JsiSkWrappingSkPtrHostObject<SkTextBlob>(std::move(context),
|
26
26
|
std::move(shader)) {}
|
27
27
|
|
28
|
+
size_t getMemoryPressure() const override {
|
29
|
+
auto textBlob = getObject();
|
30
|
+
if (!textBlob)
|
31
|
+
return 0;
|
32
|
+
|
33
|
+
// For SkTextBlob, we'll estimate based on glyph data and text positioning
|
34
|
+
// SkTextBlob doesn't provide direct size methods, so estimate
|
35
|
+
// conservatively
|
36
|
+
return textBlob->bounds().width() * textBlob->bounds().height() +
|
37
|
+
1024; // Area estimation + base overhead
|
38
|
+
}
|
39
|
+
|
28
40
|
EXPORT_JSI_API_TYPENAME(JsiSkTextBlob, TextBlob)
|
29
41
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTextBlob, dispose))
|
30
42
|
};
|
@@ -28,9 +28,10 @@ public:
|
|
28
28
|
auto str = arguments[0].asString(runtime).utf8(runtime);
|
29
29
|
auto font = JsiSkFont::fromValue(runtime, arguments[1]);
|
30
30
|
auto textBlob = SkTextBlob::MakeFromString(str.c_str(), *font);
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
auto hostObjectInstance =
|
32
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob));
|
33
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
34
|
+
runtime, hostObjectInstance, getContext());
|
34
35
|
}
|
35
36
|
|
36
37
|
JSI_HOST_FUNCTION(MakeFromGlyphs) {
|
@@ -46,9 +47,10 @@ public:
|
|
46
47
|
auto textBlob =
|
47
48
|
SkTextBlob::MakeFromText(glyphs.data(), glyphs.size() * bytesPerGlyph,
|
48
49
|
*font, SkTextEncoding::kGlyphID);
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
auto hostObjectInstance =
|
51
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob));
|
52
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
53
|
+
runtime, hostObjectInstance, getContext());
|
52
54
|
}
|
53
55
|
|
54
56
|
JSI_HOST_FUNCTION(MakeFromRSXform) {
|
@@ -66,9 +68,10 @@ public:
|
|
66
68
|
auto x = SkSpan(rsxforms.data(), rsxforms.size());
|
67
69
|
auto textBlob =
|
68
70
|
SkTextBlob::MakeFromRSXform(str.c_str(), str.length(), x, *font);
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
auto hostObjectInstance =
|
72
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob));
|
73
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
74
|
+
runtime, hostObjectInstance, getContext());
|
72
75
|
}
|
73
76
|
|
74
77
|
JSI_HOST_FUNCTION(MakeFromRSXformGlyphs) {
|
@@ -94,9 +97,10 @@ public:
|
|
94
97
|
auto textBlob = SkTextBlob::MakeFromRSXform(
|
95
98
|
glyphs.data(), glyphs.size() * bytesPerGlyph, x, *font,
|
96
99
|
SkTextEncoding::kGlyphID);
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
+
auto hostObjectInstance =
|
101
|
+
std::make_shared<JsiSkTextBlob>(getContext(), std::move(textBlob));
|
102
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
103
|
+
runtime, hostObjectInstance, getContext());
|
100
104
|
}
|
101
105
|
|
102
106
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTextBlobFactory, MakeFromText),
|
@@ -105,6 +109,8 @@ public:
|
|
105
109
|
JSI_EXPORT_FUNC(JsiSkTextBlobFactory,
|
106
110
|
MakeFromRSXformGlyphs), )
|
107
111
|
|
112
|
+
size_t getMemoryPressure() const override { return 2048; }
|
113
|
+
|
108
114
|
explicit JsiSkTextBlobFactory(std::shared_ptr<RNSkPlatformContext> context)
|
109
115
|
: JsiSkHostObject(std::move(context)) {}
|
110
116
|
};
|
package/cpp/api/JsiSkTypeface.h
CHANGED
@@ -53,15 +53,31 @@ public:
|
|
53
53
|
return jsiGlyphIDs;
|
54
54
|
}
|
55
55
|
|
56
|
+
size_t getMemoryPressure() const override {
|
57
|
+
auto typeface = getObject();
|
58
|
+
if (!typeface) {
|
59
|
+
return 0;
|
60
|
+
}
|
61
|
+
|
62
|
+
// Typefaces can be quite large as they contain font data
|
63
|
+
// Since SkTypeface doesn't provide a direct memory usage method,
|
64
|
+
// estimate based on glyph count (typically ranges from 64KB to several MB)
|
65
|
+
int glyphCount = typeface->countGlyphs();
|
66
|
+
return glyphCount > 0
|
67
|
+
? glyphCount * 64
|
68
|
+
: 65536; // 64 bytes per glyph estimate, or 64KB minimum
|
69
|
+
}
|
70
|
+
|
56
71
|
/**
|
57
72
|
Returns the jsi object from a host object of this type
|
58
73
|
*/
|
59
74
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
60
75
|
std::shared_ptr<RNSkPlatformContext> context,
|
61
76
|
sk_sp<SkTypeface> tf) {
|
62
|
-
|
63
|
-
|
64
|
-
|
77
|
+
auto hostObjectInstance =
|
78
|
+
std::make_shared<JsiSkTypeface>(context, std::move(tf));
|
79
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
80
|
+
runtime, hostObjectInstance, context);
|
65
81
|
}
|
66
82
|
};
|
67
83
|
|
@@ -22,10 +22,14 @@ public:
|
|
22
22
|
if (typeface == nullptr) {
|
23
23
|
return jsi::Value::null();
|
24
24
|
}
|
25
|
-
|
26
|
-
|
25
|
+
auto hostObjectInstance =
|
26
|
+
std::make_shared<JsiSkTypeface>(getContext(), std::move(typeface));
|
27
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
28
|
+
runtime, hostObjectInstance, getContext());
|
27
29
|
}
|
28
30
|
|
31
|
+
size_t getMemoryPressure() const override { return 1024; }
|
32
|
+
|
29
33
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypefaceFactory,
|
30
34
|
MakeFreeTypeFaceFromData))
|
31
35
|
|
@@ -59,8 +59,10 @@ public:
|
|
59
59
|
if (!typeface) {
|
60
60
|
throw std::runtime_error("Could not find font style for " + name);
|
61
61
|
}
|
62
|
-
|
63
|
-
|
62
|
+
auto hostObjectInstance =
|
63
|
+
std::make_shared<JsiSkTypeface>(getContext(), std::move(typeface));
|
64
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
65
|
+
runtime, hostObjectInstance, getContext());
|
64
66
|
}
|
65
67
|
|
66
68
|
JSI_HOST_FUNCTION(countFamilies) { return getObject()->countFamilies(); }
|
@@ -77,15 +79,18 @@ public:
|
|
77
79
|
: JsiSkWrappingSkPtrHostObject(std::move(context),
|
78
80
|
std::move(tfProvider)) {}
|
79
81
|
|
82
|
+
size_t getMemoryPressure() const override { return 4096; }
|
83
|
+
|
80
84
|
/**
|
81
85
|
Returns the jsi object from a host object of this type
|
82
86
|
*/
|
83
87
|
static jsi::Value toValue(jsi::Runtime &runtime,
|
84
88
|
std::shared_ptr<RNSkPlatformContext> context,
|
85
89
|
sk_sp<para::TypefaceFontProvider> tfProvider) {
|
86
|
-
|
87
|
-
|
88
|
-
|
90
|
+
auto provider = std::make_shared<JsiSkTypefaceFontProvider>(
|
91
|
+
std::move(context), std::move(tfProvider));
|
92
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, provider,
|
93
|
+
context);
|
89
94
|
}
|
90
95
|
};
|
91
96
|
|
@@ -17,13 +17,16 @@ namespace para = skia::textlayout;
|
|
17
17
|
class JsiSkTypefaceFontProviderFactory : public JsiSkHostObject {
|
18
18
|
public:
|
19
19
|
JSI_HOST_FUNCTION(Make) {
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
auto provider = std::make_shared<JsiSkTypefaceFontProvider>(
|
21
|
+
getContext(), sk_make_sp<para::TypefaceFontProvider>());
|
22
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, provider,
|
23
|
+
getContext());
|
23
24
|
}
|
24
25
|
|
25
26
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypefaceFontProviderFactory, Make))
|
26
27
|
|
28
|
+
size_t getMemoryPressure() const override { return 2048; }
|
29
|
+
|
27
30
|
explicit JsiSkTypefaceFontProviderFactory(
|
28
31
|
std::shared_ptr<RNSkPlatformContext> context)
|
29
32
|
: JsiSkHostObject(std::move(context)) {}
|
package/cpp/api/JsiSkVertices.h
CHANGED
@@ -29,14 +29,24 @@ public:
|
|
29
29
|
|
30
30
|
JSI_HOST_FUNCTION(bounds) {
|
31
31
|
const auto &result = getObject()->bounds();
|
32
|
-
|
33
|
-
|
32
|
+
auto hostObjectInstance = std::make_shared<JsiSkRect>(getContext(), result);
|
33
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
34
|
+
runtime, hostObjectInstance, getContext());
|
34
35
|
}
|
35
36
|
|
36
37
|
JSI_HOST_FUNCTION(uniqueID) {
|
37
38
|
return static_cast<double>(getObject()->uniqueID());
|
38
39
|
}
|
39
40
|
|
41
|
+
size_t getMemoryPressure() const override {
|
42
|
+
auto vertices = getObject();
|
43
|
+
if (!vertices)
|
44
|
+
return 0;
|
45
|
+
|
46
|
+
// SkVertices provides approximateBytesUsed() to estimate memory usage
|
47
|
+
return vertices->approximateSize();
|
48
|
+
}
|
49
|
+
|
40
50
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkVertices, bounds),
|
41
51
|
JSI_EXPORT_FUNC(JsiSkVertices, uniqueID),
|
42
52
|
JSI_EXPORT_FUNC(JsiSkVertices, dispose))
|
@@ -146,9 +156,10 @@ public:
|
|
146
156
|
texs.size() > 0 ? texs.data() : nullptr,
|
147
157
|
colors.size() > 0 ? colors.data() : nullptr,
|
148
158
|
indicesSize, indices.data());
|
149
|
-
|
150
|
-
|
151
|
-
|
159
|
+
auto hostObjectInstance =
|
160
|
+
std::make_shared<JsiSkVertices>(context, std::move(vertices));
|
161
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
162
|
+
runtime, hostObjectInstance, context);
|
152
163
|
};
|
153
164
|
}
|
154
165
|
};
|
package/cpp/api/JsiSkiaContext.h
CHANGED
@@ -37,9 +37,10 @@ public:
|
|
37
37
|
if (surface == nullptr) {
|
38
38
|
return jsi::Value::null();
|
39
39
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
auto hostObjectInstance =
|
41
|
+
std::make_shared<JsiSkSurface>(getContext(), std::move(surface));
|
42
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
43
|
+
runtime, hostObjectInstance, getContext());
|
43
44
|
}
|
44
45
|
|
45
46
|
JSI_HOST_FUNCTION(present) {
|
@@ -54,6 +55,8 @@ public:
|
|
54
55
|
std::shared_ptr<WindowContext> ctx)
|
55
56
|
: JsiSkWrappingSharedPtrHostObject(std::move(context), std::move(ctx)) {}
|
56
57
|
|
58
|
+
size_t getMemoryPressure() const override { return 8192; }
|
59
|
+
|
57
60
|
/**
|
58
61
|
* Creates the function for construction a new instance of the SkFont
|
59
62
|
* wrapper
|
@@ -75,9 +78,10 @@ public:
|
|
75
78
|
auto result =
|
76
79
|
context->makeContextFromNativeSurface(surface, width, height);
|
77
80
|
// Return the newly constructed object
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
auto hostObjectInstance =
|
82
|
+
std::make_shared<JsiSkiaContext>(context, std::move(result));
|
83
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
84
|
+
runtime, hostObjectInstance, context);
|
81
85
|
};
|
82
86
|
}
|
83
87
|
};
|
@@ -51,13 +51,16 @@ public:
|
|
51
51
|
if (!managedAnimation->_animation) {
|
52
52
|
return jsi::Value::null();
|
53
53
|
}
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
auto skottie = std::make_shared<JsiSkSkottie>(getContext(),
|
55
|
+
std::move(managedAnimation));
|
56
|
+
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(runtime, skottie,
|
57
|
+
getContext());
|
57
58
|
}
|
58
59
|
|
59
60
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkottieFactory, Make))
|
60
61
|
|
62
|
+
size_t getMemoryPressure() const override { return 4096; }
|
63
|
+
|
61
64
|
explicit JsiSkottieFactory(std::shared_ptr<RNSkPlatformContext> context)
|
62
65
|
: JsiSkHostObject(std::move(context)) {}
|
63
66
|
};
|