@shopify/react-native-skia 2.4.19 → 2.4.21
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/apple/MetalContext.h +2 -3
- package/apple/SkiaCVPixelBufferUtils.h +5 -6
- package/apple/SkiaCVPixelBufferUtils.mm +21 -13
- package/cpp/api/JsiSkContourMeasureIter.h +1 -1
- package/cpp/api/JsiSkFont.h +3 -1
- package/cpp/api/JsiSkFontStyle.h +3 -1
- package/cpp/api/JsiSkHostObjects.h +13 -1
- package/cpp/api/JsiSkImage.h +17 -19
- package/cpp/api/JsiSkImageInfo.h +3 -1
- package/cpp/api/JsiSkMatrix.h +3 -1
- package/cpp/api/JsiSkPaint.h +3 -1
- package/cpp/api/JsiSkPicture.h +13 -18
- package/cpp/api/JsiSkPoint.h +3 -1
- package/cpp/api/JsiSkRRect.h +3 -1
- package/cpp/api/JsiSkRSXform.h +3 -1
- package/cpp/api/JsiSkRect.h +3 -1
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +1 -1
- package/cpp/api/JsiSkSVGFactory.h +1 -1
- package/cpp/api/JsiSkSurface.h +13 -18
- package/cpp/jsi2/NativeObject.h +6 -1
- package/lib/commonjs/renderer/Offscreen.d.ts +3 -3
- package/lib/commonjs/renderer/Offscreen.js.map +1 -1
- package/lib/commonjs/skia/types/Image/Image.d.ts +2 -1
- package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
- package/lib/module/renderer/Offscreen.d.ts +3 -3
- package/lib/module/renderer/Offscreen.js.map +1 -1
- package/lib/module/skia/types/Image/Image.d.ts +2 -1
- package/lib/module/skia/types/Image/Image.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/Offscreen.d.ts +2 -2
- package/lib/typescript/lib/module/renderer/Offscreen.d.ts +2 -2
- package/lib/typescript/src/renderer/Offscreen.d.ts +3 -3
- package/lib/typescript/src/skia/types/Image/Image.d.ts +2 -1
- package/package.json +1 -1
- package/src/renderer/Offscreen.tsx +9 -3
- package/src/skia/types/Image/Image.ts +2 -1
package/apple/MetalContext.h
CHANGED
|
@@ -65,7 +65,6 @@ public:
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
sk_sp<SkImage> MakeImageFromBuffer(void *buffer) {
|
|
68
|
-
|
|
69
68
|
CVPixelBufferRef sampleBuffer = (CVPixelBufferRef)buffer;
|
|
70
69
|
SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat format =
|
|
71
70
|
SkiaCVPixelBufferUtils::getCVPixelBufferBaseFormat(sampleBuffer);
|
|
@@ -73,12 +72,12 @@ public:
|
|
|
73
72
|
case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::rgb: {
|
|
74
73
|
// CVPixelBuffer is in any RGB format, single-plane
|
|
75
74
|
return SkiaCVPixelBufferUtils::RGB::makeSkImageFromCVPixelBuffer(
|
|
76
|
-
_directContext.get(), sampleBuffer);
|
|
75
|
+
_device, _directContext.get(), sampleBuffer);
|
|
77
76
|
}
|
|
78
77
|
case SkiaCVPixelBufferUtils::CVPixelBufferBaseFormat::yuv: {
|
|
79
78
|
// CVPixelBuffer is in any YUV format, multi-plane
|
|
80
79
|
return SkiaCVPixelBufferUtils::YUV::makeSkImageFromCVPixelBuffer(
|
|
81
|
-
_directContext.get(), sampleBuffer);
|
|
80
|
+
_device, _directContext.get(), sampleBuffer);
|
|
82
81
|
}
|
|
83
82
|
default:
|
|
84
83
|
[[unlikely]] {
|
|
@@ -84,7 +84,7 @@ public:
|
|
|
84
84
|
CVPixelBuffer.
|
|
85
85
|
*/
|
|
86
86
|
static sk_sp<SkImage>
|
|
87
|
-
makeSkImageFromCVPixelBuffer(GrDirectContext *context,
|
|
87
|
+
makeSkImageFromCVPixelBuffer(id<MTLDevice> device, GrDirectContext *context,
|
|
88
88
|
CVPixelBufferRef pixelBuffer);
|
|
89
89
|
|
|
90
90
|
private:
|
|
@@ -98,7 +98,7 @@ public:
|
|
|
98
98
|
CVPixelBuffer.
|
|
99
99
|
*/
|
|
100
100
|
static sk_sp<SkImage>
|
|
101
|
-
makeSkImageFromCVPixelBuffer(GrDirectContext *context,
|
|
101
|
+
makeSkImageFromCVPixelBuffer(id<MTLDevice> device, GrDirectContext *context,
|
|
102
102
|
CVPixelBufferRef pixelBuffer);
|
|
103
103
|
|
|
104
104
|
private:
|
|
@@ -109,10 +109,9 @@ public:
|
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
private:
|
|
112
|
-
static CVMetalTextureCacheRef getTextureCache();
|
|
113
|
-
static TextureHolder *
|
|
114
|
-
|
|
115
|
-
size_t planeIndex);
|
|
112
|
+
static CVMetalTextureCacheRef getTextureCache(id<MTLDevice> device);
|
|
113
|
+
static TextureHolder *getSkiaTextureForCVPixelBufferPlane(
|
|
114
|
+
id<MTLDevice> device, CVPixelBufferRef pixelBuffer, size_t planeIndex);
|
|
116
115
|
static MTLPixelFormat
|
|
117
116
|
getMTLPixelFormatForCVPixelBufferPlane(CVPixelBufferRef pixelBuffer,
|
|
118
117
|
size_t planeIndex);
|
|
@@ -134,13 +134,14 @@ SkColorType SkiaCVPixelBufferUtils::RGB::getCVPixelBufferColorType(
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
sk_sp<SkImage> SkiaCVPixelBufferUtils::RGB::makeSkImageFromCVPixelBuffer(
|
|
137
|
-
GrDirectContext *context,
|
|
137
|
+
id<MTLDevice> device, GrDirectContext *context,
|
|
138
|
+
CVPixelBufferRef pixelBuffer) {
|
|
138
139
|
// 1. Get Skia color type for RGB buffer
|
|
139
140
|
SkColorType colorType = getCVPixelBufferColorType(pixelBuffer);
|
|
140
141
|
|
|
141
142
|
// 2. Get texture, RGB buffers only have one plane
|
|
142
|
-
TextureHolder *texture =
|
|
143
|
-
|
|
143
|
+
TextureHolder *texture = getSkiaTextureForCVPixelBufferPlane(
|
|
144
|
+
device, pixelBuffer, /* planeIndex */ 0);
|
|
144
145
|
|
|
145
146
|
// 3. Convert to image with manual memory cleanup
|
|
146
147
|
return SkImages::BorrowTextureFrom(
|
|
@@ -152,15 +153,22 @@ sk_sp<SkImage> SkiaCVPixelBufferUtils::RGB::makeSkImageFromCVPixelBuffer(
|
|
|
152
153
|
// pragma MARK: YUV
|
|
153
154
|
|
|
154
155
|
sk_sp<SkImage> SkiaCVPixelBufferUtils::YUV::makeSkImageFromCVPixelBuffer(
|
|
155
|
-
GrDirectContext *context,
|
|
156
|
+
id<MTLDevice> device, GrDirectContext *context,
|
|
157
|
+
CVPixelBufferRef pixelBuffer) {
|
|
156
158
|
// 1. Get all planes (YUV, Y_UV, Y_U_V or Y_U_V_A)
|
|
157
|
-
size_t planesCount = CVPixelBufferGetPlaneCount(pixelBuffer);
|
|
159
|
+
const size_t planesCount = CVPixelBufferGetPlaneCount(pixelBuffer);
|
|
160
|
+
if (planesCount > SkYUVAInfo::kMaxPlanes) [[unlikely]] {
|
|
161
|
+
throw std::runtime_error(
|
|
162
|
+
"CVPixelBuffer has " + std::to_string(planesCount) +
|
|
163
|
+
" textures, but the platform only supports a maximum of " +
|
|
164
|
+
std::to_string(SkYUVAInfo::kMaxPlanes) + " textures!");
|
|
165
|
+
}
|
|
158
166
|
MultiTexturesHolder *texturesHolder = new MultiTexturesHolder();
|
|
159
|
-
GrBackendTexture textures[
|
|
167
|
+
GrBackendTexture textures[SkYUVAInfo::kMaxPlanes];
|
|
160
168
|
|
|
161
169
|
for (size_t planeIndex = 0; planeIndex < planesCount; planeIndex++) {
|
|
162
170
|
TextureHolder *textureHolder =
|
|
163
|
-
getSkiaTextureForCVPixelBufferPlane(pixelBuffer, planeIndex);
|
|
171
|
+
getSkiaTextureForCVPixelBufferPlane(device, pixelBuffer, planeIndex);
|
|
164
172
|
textures[planeIndex] = textureHolder->toGrBackendTexture();
|
|
165
173
|
texturesHolder->addTexture(textureHolder);
|
|
166
174
|
}
|
|
@@ -282,9 +290,9 @@ SkYUVColorSpace SkiaCVPixelBufferUtils::YUV::getColorspace(OSType pixelFormat) {
|
|
|
282
290
|
// pragma MARK: CVPixelBuffer -> Skia Texture
|
|
283
291
|
|
|
284
292
|
TextureHolder *SkiaCVPixelBufferUtils::getSkiaTextureForCVPixelBufferPlane(
|
|
285
|
-
CVPixelBufferRef pixelBuffer, size_t planeIndex) {
|
|
293
|
+
id<MTLDevice> device, CVPixelBufferRef pixelBuffer, size_t planeIndex) {
|
|
286
294
|
// 1. Get cache
|
|
287
|
-
CVMetalTextureCacheRef textureCache = getTextureCache();
|
|
295
|
+
CVMetalTextureCacheRef textureCache = getTextureCache(device);
|
|
288
296
|
|
|
289
297
|
// 2. Get MetalTexture from CMSampleBuffer
|
|
290
298
|
size_t width = CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex);
|
|
@@ -308,13 +316,13 @@ TextureHolder *SkiaCVPixelBufferUtils::getSkiaTextureForCVPixelBufferPlane(
|
|
|
308
316
|
|
|
309
317
|
// pragma MARK: getTextureCache()
|
|
310
318
|
|
|
311
|
-
CVMetalTextureCacheRef
|
|
319
|
+
CVMetalTextureCacheRef
|
|
320
|
+
SkiaCVPixelBufferUtils::getTextureCache(id<MTLDevice> device) {
|
|
312
321
|
static CVMetalTextureCacheRef textureCache = nil;
|
|
313
322
|
if (textureCache == nil) {
|
|
314
323
|
// Create a new Texture Cache
|
|
315
|
-
auto result = CVMetalTextureCacheCreate(kCFAllocatorDefault, nil,
|
|
316
|
-
|
|
317
|
-
&textureCache);
|
|
324
|
+
auto result = CVMetalTextureCacheCreate(kCFAllocatorDefault, nil, device,
|
|
325
|
+
nil, &textureCache);
|
|
318
326
|
if (result != kCVReturnSuccess || textureCache == nil) {
|
|
319
327
|
throw std::runtime_error("Failed to create Metal Texture Cache!");
|
|
320
328
|
}
|
|
@@ -47,7 +47,7 @@ public:
|
|
|
47
47
|
JSI_EXPORT_FUNC(JsiSkContourMeasureIter, dispose))
|
|
48
48
|
|
|
49
49
|
size_t getMemoryPressure() const override {
|
|
50
|
-
return sizeof(SkContourMeasureIter);
|
|
50
|
+
return std::max(sizeof(SkContourMeasureIter), kMinMemoryPressure);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
std::string getObjectType() const override {
|
package/cpp/api/JsiSkFont.h
CHANGED
|
@@ -279,7 +279,9 @@ public:
|
|
|
279
279
|
: JsiSkWrappingSharedPtrHostObject(std::move(context),
|
|
280
280
|
std::make_shared<SkFont>(font)) {}
|
|
281
281
|
|
|
282
|
-
size_t getMemoryPressure() const override {
|
|
282
|
+
size_t getMemoryPressure() const override {
|
|
283
|
+
return std::max(sizeof(SkFont), kMinMemoryPressure);
|
|
284
|
+
}
|
|
283
285
|
|
|
284
286
|
std::string getObjectType() const override { return "JsiSkFont"; }
|
|
285
287
|
|
package/cpp/api/JsiSkFontStyle.h
CHANGED
|
@@ -56,7 +56,9 @@ public:
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
size_t getMemoryPressure() const override {
|
|
59
|
+
size_t getMemoryPressure() const override {
|
|
60
|
+
return std::max(sizeof(SkFontStyle), kMinMemoryPressure);
|
|
61
|
+
}
|
|
60
62
|
|
|
61
63
|
std::string getObjectType() const override { return "JsiSkFontStyle"; }
|
|
62
64
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <algorithm>
|
|
3
4
|
#include <memory>
|
|
4
5
|
#include <string>
|
|
5
6
|
#include <utility>
|
|
@@ -12,6 +13,11 @@ namespace RNSkia {
|
|
|
12
13
|
|
|
13
14
|
namespace jsi = facebook::jsi;
|
|
14
15
|
|
|
16
|
+
// Minimum memory pressure reported for any host object.
|
|
17
|
+
// This accounts for C++ wrapper overhead and ensures dispose() never
|
|
18
|
+
// increases reported memory pressure (which would defeat its purpose).
|
|
19
|
+
static constexpr size_t kMinMemoryPressure = 256;
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* Base class for jsi host objects - these are all implemented as JsiHostObjects
|
|
17
23
|
* and has a pointer to the platform context.
|
|
@@ -139,6 +145,10 @@ public:
|
|
|
139
145
|
* macro.
|
|
140
146
|
*/
|
|
141
147
|
JSI_HOST_FUNCTION(dispose) {
|
|
148
|
+
if (!isDisposed()) {
|
|
149
|
+
thisValue.asObject(runtime).setExternalMemoryPressure(runtime,
|
|
150
|
+
kMinMemoryPressure);
|
|
151
|
+
}
|
|
142
152
|
safeDispose();
|
|
143
153
|
return jsi::Value::undefined();
|
|
144
154
|
}
|
|
@@ -153,7 +163,9 @@ protected:
|
|
|
153
163
|
/**
|
|
154
164
|
* Returns true if the object has been disposed.
|
|
155
165
|
*/
|
|
156
|
-
bool isDisposed() const {
|
|
166
|
+
bool isDisposed() const {
|
|
167
|
+
return _isDisposed.load(std::memory_order_acquire);
|
|
168
|
+
}
|
|
157
169
|
|
|
158
170
|
/**
|
|
159
171
|
* Returns the underlying object without checking if disposed.
|
package/cpp/api/JsiSkImage.h
CHANGED
|
@@ -249,6 +249,9 @@ public:
|
|
|
249
249
|
}
|
|
250
250
|
auto rasterImage = image->makeRasterImage(grContext);
|
|
251
251
|
#endif
|
|
252
|
+
if (!rasterImage) {
|
|
253
|
+
return jsi::Value::null();
|
|
254
|
+
}
|
|
252
255
|
auto hostObjectInstance =
|
|
253
256
|
std::make_shared<JsiSkImage>(getContext(), std::move(rasterImage));
|
|
254
257
|
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
|
|
@@ -289,31 +292,26 @@ public:
|
|
|
289
292
|
std::move(image)) {
|
|
290
293
|
// Get the dispatcher for the current thread
|
|
291
294
|
_dispatcher = Dispatcher::getDispatcher();
|
|
292
|
-
// Process any pending operations
|
|
295
|
+
// Process any pending operations (e.g. deletions of previous resources)
|
|
293
296
|
_dispatcher->processQueue();
|
|
294
297
|
}
|
|
295
298
|
|
|
296
|
-
protected:
|
|
297
|
-
void releaseResources() override {
|
|
298
|
-
// Queue deletion on the creation thread if needed
|
|
299
|
-
auto image = getObjectUnchecked();
|
|
300
|
-
if (image && _dispatcher) {
|
|
301
|
-
_dispatcher->run([image]() {
|
|
302
|
-
// Image will be deleted when this lambda is destroyed
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
// Clear the object
|
|
306
|
-
JsiSkWrappingSkPtrHostObject<SkImage>::releaseResources();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
299
|
public:
|
|
310
300
|
~JsiSkImage() override {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
301
|
+
if (!isDisposed()) {
|
|
302
|
+
// This JSI Object is being deleted from a GC, which might happen
|
|
303
|
+
// on a separate Thread. GPU resources (like SkImage) must be deleted
|
|
304
|
+
// on the same Thread they were created on, so in this case we schedule
|
|
305
|
+
// deletion to run on the Thread this Object was created on.
|
|
306
|
+
auto image = getObjectUnchecked();
|
|
307
|
+
if (image && _dispatcher) {
|
|
308
|
+
_dispatcher->run([image]() {
|
|
309
|
+
// Image will be deleted when this lambda is destroyed, on the
|
|
310
|
+
// original Thread.
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
releaseResources();
|
|
314
314
|
}
|
|
315
|
-
// Use the same cleanup path as dispose()
|
|
316
|
-
releaseResources();
|
|
317
315
|
}
|
|
318
316
|
|
|
319
317
|
size_t getMemoryPressure() const override {
|
package/cpp/api/JsiSkImageInfo.h
CHANGED
|
@@ -69,7 +69,9 @@ public:
|
|
|
69
69
|
return static_cast<double>(getObject()->alphaType());
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
size_t getMemoryPressure() const override {
|
|
72
|
+
size_t getMemoryPressure() const override {
|
|
73
|
+
return std::max(sizeof(SkImageInfo), kMinMemoryPressure);
|
|
74
|
+
}
|
|
73
75
|
|
|
74
76
|
std::string getObjectType() const override { return "JsiSkImageInfo"; }
|
|
75
77
|
|
package/cpp/api/JsiSkMatrix.h
CHANGED
|
@@ -166,7 +166,9 @@ public:
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
size_t getMemoryPressure() const override {
|
|
169
|
+
size_t getMemoryPressure() const override {
|
|
170
|
+
return std::max(sizeof(SkMatrix), kMinMemoryPressure);
|
|
171
|
+
}
|
|
170
172
|
|
|
171
173
|
std::string getObjectType() const override { return "JsiSkMatrix"; }
|
|
172
174
|
|
package/cpp/api/JsiSkPaint.h
CHANGED
|
@@ -209,7 +209,9 @@ public:
|
|
|
209
209
|
setObject(std::make_shared<SkPaint>(std::move(paint)));
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
size_t getMemoryPressure() const override {
|
|
212
|
+
size_t getMemoryPressure() const override {
|
|
213
|
+
return std::max(sizeof(SkPaint), kMinMemoryPressure);
|
|
214
|
+
}
|
|
213
215
|
|
|
214
216
|
std::string getObjectType() const override { return "JsiSkPaint"; }
|
|
215
217
|
|
package/cpp/api/JsiSkPicture.h
CHANGED
|
@@ -34,27 +34,22 @@ public:
|
|
|
34
34
|
_dispatcher->processQueue();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
protected:
|
|
38
|
-
void releaseResources() override {
|
|
39
|
-
// Queue deletion on the creation thread if needed
|
|
40
|
-
auto picture = getObjectUnchecked();
|
|
41
|
-
if (picture && _dispatcher) {
|
|
42
|
-
_dispatcher->run([picture]() {
|
|
43
|
-
// Picture will be deleted when this lambda is destroyed
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
// Clear the object
|
|
47
|
-
JsiSkWrappingSkPtrHostObject<SkPicture>::releaseResources();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
37
|
public:
|
|
51
38
|
~JsiSkPicture() override {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
if (!isDisposed()) {
|
|
40
|
+
// This JSI Object is being deleted from a GC, which might happen
|
|
41
|
+
// on a separate Thread. GPU resources (like SkPicture) must be deleted
|
|
42
|
+
// on the same Thread they were created on, so in this case we schedule
|
|
43
|
+
// deletion to run on the Thread this Object was created on.
|
|
44
|
+
auto picture = getObjectUnchecked();
|
|
45
|
+
if (picture && _dispatcher) {
|
|
46
|
+
_dispatcher->run([picture]() {
|
|
47
|
+
// Picture will be deleted when this lambda is destroyed, on the
|
|
48
|
+
// original Thread.
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
releaseResources();
|
|
55
52
|
}
|
|
56
|
-
// Use the same cleanup path as dispose()
|
|
57
|
-
releaseResources();
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
JSI_HOST_FUNCTION(makeShader) {
|
package/cpp/api/JsiSkPoint.h
CHANGED
|
@@ -62,7 +62,9 @@ public:
|
|
|
62
62
|
context);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
size_t getMemoryPressure() const override {
|
|
65
|
+
size_t getMemoryPressure() const override {
|
|
66
|
+
return std::max(sizeof(SkPoint), kMinMemoryPressure);
|
|
67
|
+
}
|
|
66
68
|
|
|
67
69
|
std::string getObjectType() const override { return "JsiSkPoint"; }
|
|
68
70
|
|
package/cpp/api/JsiSkRRect.h
CHANGED
|
@@ -106,7 +106,9 @@ public:
|
|
|
106
106
|
context);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
size_t getMemoryPressure() const override {
|
|
109
|
+
size_t getMemoryPressure() const override {
|
|
110
|
+
return std::max(sizeof(SkRRect), kMinMemoryPressure);
|
|
111
|
+
}
|
|
110
112
|
|
|
111
113
|
std::string getObjectType() const override { return "JsiSkRRect"; }
|
|
112
114
|
|
package/cpp/api/JsiSkRSXform.h
CHANGED
|
@@ -111,7 +111,9 @@ public:
|
|
|
111
111
|
context);
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
size_t getMemoryPressure() const override {
|
|
114
|
+
size_t getMemoryPressure() const override {
|
|
115
|
+
return std::max(sizeof(SkRSXform), kMinMemoryPressure);
|
|
116
|
+
}
|
|
115
117
|
|
|
116
118
|
std::string getObjectType() const override { return "JsiSkRSXform"; }
|
|
117
119
|
|
package/cpp/api/JsiSkRect.h
CHANGED
|
@@ -100,7 +100,9 @@ public:
|
|
|
100
100
|
context);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
size_t getMemoryPressure() const override {
|
|
103
|
+
size_t getMemoryPressure() const override {
|
|
104
|
+
return std::max(sizeof(SkRect), kMinMemoryPressure);
|
|
105
|
+
}
|
|
104
106
|
|
|
105
107
|
std::string getObjectType() const override { return "JsiSkRect"; }
|
|
106
108
|
|
|
@@ -160,7 +160,7 @@ public:
|
|
|
160
160
|
std::move(assets));
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
size_t getMemoryPressure() const override { return
|
|
163
|
+
size_t getMemoryPressure() const override { return kMinMemoryPressure; }
|
|
164
164
|
|
|
165
165
|
std::string getObjectType() const override { return "JsiSkSVGFactory"; }
|
|
166
166
|
|
package/cpp/api/JsiSkSurface.h
CHANGED
|
@@ -45,27 +45,22 @@ public:
|
|
|
45
45
|
_dispatcher->processQueue();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
protected:
|
|
49
|
-
void releaseResources() override {
|
|
50
|
-
// Queue deletion on the creation thread if needed
|
|
51
|
-
auto surface = getObjectUnchecked();
|
|
52
|
-
if (surface && _dispatcher) {
|
|
53
|
-
_dispatcher->run([surface]() {
|
|
54
|
-
// Surface will be deleted when this lambda is destroyed
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// Clear the object
|
|
58
|
-
JsiSkWrappingSkPtrHostObject<SkSurface>::releaseResources();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
48
|
public:
|
|
62
49
|
~JsiSkSurface() override {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
if (!isDisposed()) {
|
|
51
|
+
// This JSI Object is being deleted from a GC, which might happen
|
|
52
|
+
// on a separate Thread. GPU resources (like SkSurface) must be deleted
|
|
53
|
+
// on the same Thread they were created on, so in this case we schedule
|
|
54
|
+
// deletion to run on the Thread this Object was created on.
|
|
55
|
+
auto surface = getObjectUnchecked();
|
|
56
|
+
if (surface && _dispatcher) {
|
|
57
|
+
_dispatcher->run([surface]() {
|
|
58
|
+
// Surface will be deleted when this lambda is destroyed, on the
|
|
59
|
+
// original Thread.
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
releaseResources();
|
|
66
63
|
}
|
|
67
|
-
// Use the same cleanup path as dispose()
|
|
68
|
-
releaseResources();
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
EXPORT_JSI_API_TYPENAME(JsiSkSurface, Surface)
|
package/cpp/jsi2/NativeObject.h
CHANGED
|
@@ -28,6 +28,11 @@ namespace rnwgpu {
|
|
|
28
28
|
|
|
29
29
|
namespace jsi = facebook::jsi;
|
|
30
30
|
|
|
31
|
+
// Minimum memory pressure reported for any native object.
|
|
32
|
+
// This accounts for C++ wrapper overhead and ensures dispose() never
|
|
33
|
+
// increases reported memory pressure (which would defeat its purpose).
|
|
34
|
+
static constexpr size_t kMinMemoryPressure = 256;
|
|
35
|
+
|
|
31
36
|
// Forward declaration
|
|
32
37
|
template <typename Derived> class NativeObject;
|
|
33
38
|
|
|
@@ -384,7 +389,7 @@ public:
|
|
|
384
389
|
/**
|
|
385
390
|
* Memory pressure for GC hints. Override in derived classes.
|
|
386
391
|
*/
|
|
387
|
-
virtual size_t getMemoryPressure() { return
|
|
392
|
+
virtual size_t getMemoryPressure() { return kMinMemoryPressure; }
|
|
388
393
|
|
|
389
394
|
/**
|
|
390
395
|
* Set the creation runtime. Called during create().
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
|
-
import type { SkPicture, SkRect, SkSize } from "../skia/types";
|
|
2
|
+
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
|
|
3
3
|
export declare const isOnMainThread: () => boolean;
|
|
4
4
|
export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => Promise<SkPicture>;
|
|
5
|
-
export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<
|
|
6
|
-
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) =>
|
|
5
|
+
export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<SkImage | null>;
|
|
6
|
+
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) => SkImage | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_skia","require","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","bounds","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaSGRoot","render","drawOnCanvas","picture","finishRecordingAsPicture","dispose","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaSGRoot(Skia);\n await root.render(element);\n root.drawOnCanvas(canvas);\n const picture = recorder.finishRecordingAsPicture();\n recorder.dispose();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = async (element: ReactElement
|
|
1
|
+
{"version":3,"names":["_skia","require","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","bounds","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaSGRoot","render","drawOnCanvas","picture","finishRecordingAsPicture","dispose","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaSGRoot(Skia);\n await root.render(element);\n root.drawOnCanvas(canvas);\n const picture = recorder.finishRecordingAsPicture();\n recorder.dispose();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = async (\n element: ReactElement,\n size: SkSize\n): Promise<SkImage | null> => {\n return drawAsImageFromPicture(await drawAsPicture(element), size);\n};\n\nexport const drawAsImageFromPicture = (\n picture: SkPicture,\n size: SkSize\n): SkImage | null => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;\n const canvas = surface.getCanvas();\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n return image.makeNonTextureImage();\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAEO,MAAMG,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDC,kBAAQ,CAACC,EAAE,KAAK,KAAK;AAEzB,CAAC;AAACC,OAAA,CAAAJ,cAAA,GAAAA,cAAA;AAEK,MAAMK,aAAa,GAAG,MAAAA,CAAOC,OAAqB,EAAEC,MAAe,KAAK;EAC7E,MAAMC,QAAQ,GAAGC,UAAI,CAACC,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAc,CAACL,MAAM,CAAC;EAC9C,MAAMM,IAAI,GAAG,IAAIC,sBAAU,CAACL,UAAI,CAAC;EACjC,MAAMI,IAAI,CAACE,MAAM,CAACT,OAAO,CAAC;EAC1BO,IAAI,CAACG,YAAY,CAACL,MAAM,CAAC;EACzB,MAAMM,OAAO,GAAGT,QAAQ,CAACU,wBAAwB,CAAC,CAAC;EACnDV,QAAQ,CAACW,OAAO,CAAC,CAAC;EAClBN,IAAI,CAACO,OAAO,CAAC,CAAC;EACd,OAAOH,OAAO;AAChB,CAAC;AAACb,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAMgB,WAAW,GAAG,MAAAA,CACzBf,OAAqB,EACrBgB,IAAY,KACgB;EAC5B,OAAOC,sBAAsB,CAAC,MAAMlB,aAAa,CAACC,OAAO,CAAC,EAAEgB,IAAI,CAAC;AACnE,CAAC;AAAClB,OAAA,CAAAiB,WAAA,GAAAA,WAAA;AAEK,MAAME,sBAAsB,GAAGA,CACpCN,OAAkB,EAClBK,IAAY,KACO;EACnB,SAAS;;EACT,MAAME,OAAO,GAAGf,UAAI,CAACgB,OAAO,CAACC,aAAa,CAACJ,IAAI,CAACK,KAAK,EAAEL,IAAI,CAACM,MAAM,CAAE;EACpE,MAAMjB,MAAM,GAAGa,OAAO,CAACK,SAAS,CAAC,CAAC;EAClClB,MAAM,CAACmB,WAAW,CAACb,OAAO,CAAC;EAC3BO,OAAO,CAACO,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGR,OAAO,CAACS,iBAAiB,CAAC,CAAC;EACzC,OAAOD,KAAK,CAACE,mBAAmB,CAAC,CAAC;AACpC,CAAC;AAAC9B,OAAA,CAAAmB,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -125,6 +125,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
|
125
125
|
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
|
126
126
|
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
|
127
127
|
* bitmap, or if encoded in a stream.
|
|
128
|
+
* Returns null if the conversion fails.
|
|
128
129
|
*/
|
|
129
|
-
makeNonTextureImage(): SkImage;
|
|
130
|
+
makeNonTextureImage(): SkImage | null;
|
|
130
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FilterMode","exports","MipmapMode","ImageFormat","isCubicSampling","sampling","MitchellCubicSampling","B","C","CatmullRomCubicSampling","CubicSampling","MakeCubic"],"sources":["Image.ts"],"sourcesContent":["import type { SkMatrix } from \"../Matrix\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { TileMode } from \"../ImageFilter\";\nimport type { SkShader } from \"../Shader\";\n\nimport type { ImageInfo } from \"./ImageFactory\";\n\nexport interface CubicResampler {\n B: number;\n C: number;\n}\n\nexport interface FilterOptions {\n filter: FilterMode;\n mipmap?: MipmapMode;\n}\n\nexport enum FilterMode {\n Nearest,\n Linear,\n}\n\nexport enum MipmapMode {\n None,\n Nearest,\n Linear,\n}\n\nexport enum ImageFormat {\n JPEG = 3,\n PNG = 4,\n WEBP = 6,\n}\n\nexport type SamplingOptions = CubicResampler | FilterOptions;\n\nexport const isCubicSampling = (\n sampling: SamplingOptions\n): sampling is CubicResampler => {\n \"worklet\";\n return \"B\" in sampling && \"C\" in sampling;\n};\n\nexport const MitchellCubicSampling = { B: 1 / 3.0, C: 1 / 3.0 };\nexport const CatmullRomCubicSampling = { B: 0, C: 1 / 2.0 };\nexport const CubicSampling = { B: 0, C: 0 };\nexport const MakeCubic = (B: number, C: number) => ({ B, C });\n\nexport interface SkImage extends SkJSIInstance<\"Image\"> {\n /**\n * Returns the possibly scaled height of the image.\n */\n height(): number;\n\n /**\n * Returns the possibly scaled width of the image.\n */\n width(): number;\n\n /**\n * Returns the ImageInfo describing the image.\n */\n getImageInfo(): ImageInfo;\n\n /**\n * Returns the backend texture of the image.\n * The returned object can be used to create a Skia Image object.\n * The returned object is backend specific and should be used with caution.\n * It is the caller's responsibility to ensure that the texture is not used after the image is deleted.\n * The returned object may be null if the image does not have a backend texture.\n *\n * @return backend texture of the image or null\n */\n getNativeTextureUnstable(): unknown;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param fm - The filter mode. (default nearest)\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps (default none)\n * calculated with makeCopyWithDefaultMipmaps;\n * @param localMatrix\n */\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param localMatrix\n */\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /** Encodes Image pixels, returning result as UInt8Array. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return Uint8Array with data\n */\n encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;\n\n /** Encodes Image pixels, returning result as a base64 encoded string. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return base64 encoded string of data\n */\n encodeToBase64(fmt?: ImageFormat, quality?: number): string;\n\n /** Read Image pixels\n *\n * @param srcX - optional x-axis upper left corner of the rectangle to read from\n * @param srcY - optional y-axis upper left corner of the rectangle to read from\n * @param imageInfo - optional describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX?: number,\n srcY?: number,\n imageInfo?: ImageInfo\n ): Float32Array | Uint8Array | null;\n\n /**\n * Returns raster image or lazy image. Copies SkImage backed by GPU texture\n * into CPU memory if needed. Returns original SkImage if decoded in raster\n * bitmap, or if encoded in a stream.\n */\n makeNonTextureImage(): SkImage;\n}\n"],"mappings":";;;;;;IAiBYA,UAAU,GAAAC,OAAA,CAAAD,UAAA,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAAA,IAKVE,UAAU,GAAAD,OAAA,CAAAC,UAAA,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAAA,IAMVC,WAAW,GAAAF,OAAA,CAAAE,WAAA,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAQhB,MAAMC,eAAe,GAC1BC,QAAyB,IACM;EAC/B,SAAS;;EACT,OAAO,GAAG,IAAIA,QAAQ,IAAI,GAAG,IAAIA,QAAQ;AAC3C,CAAC;AAACJ,OAAA,CAAAG,eAAA,GAAAA,eAAA;AAEK,MAAME,qBAAqB,GAAAL,OAAA,CAAAK,qBAAA,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AACxD,MAAMC,uBAAuB,GAAAR,OAAA,CAAAQ,uBAAA,GAAG;EAAEF,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AACpD,MAAME,aAAa,GAAAT,OAAA,CAAAS,aAAA,GAAG;EAAEH,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE;AAAE,CAAC;AACpC,MAAMG,SAAS,GAAGA,CAACJ,CAAS,EAAEC,CAAS,MAAM;EAAED,CAAC;EAAEC;AAAE,CAAC,CAAC;AAACP,OAAA,CAAAU,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["FilterMode","exports","MipmapMode","ImageFormat","isCubicSampling","sampling","MitchellCubicSampling","B","C","CatmullRomCubicSampling","CubicSampling","MakeCubic"],"sources":["Image.ts"],"sourcesContent":["import type { SkMatrix } from \"../Matrix\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { TileMode } from \"../ImageFilter\";\nimport type { SkShader } from \"../Shader\";\n\nimport type { ImageInfo } from \"./ImageFactory\";\n\nexport interface CubicResampler {\n B: number;\n C: number;\n}\n\nexport interface FilterOptions {\n filter: FilterMode;\n mipmap?: MipmapMode;\n}\n\nexport enum FilterMode {\n Nearest,\n Linear,\n}\n\nexport enum MipmapMode {\n None,\n Nearest,\n Linear,\n}\n\nexport enum ImageFormat {\n JPEG = 3,\n PNG = 4,\n WEBP = 6,\n}\n\nexport type SamplingOptions = CubicResampler | FilterOptions;\n\nexport const isCubicSampling = (\n sampling: SamplingOptions\n): sampling is CubicResampler => {\n \"worklet\";\n return \"B\" in sampling && \"C\" in sampling;\n};\n\nexport const MitchellCubicSampling = { B: 1 / 3.0, C: 1 / 3.0 };\nexport const CatmullRomCubicSampling = { B: 0, C: 1 / 2.0 };\nexport const CubicSampling = { B: 0, C: 0 };\nexport const MakeCubic = (B: number, C: number) => ({ B, C });\n\nexport interface SkImage extends SkJSIInstance<\"Image\"> {\n /**\n * Returns the possibly scaled height of the image.\n */\n height(): number;\n\n /**\n * Returns the possibly scaled width of the image.\n */\n width(): number;\n\n /**\n * Returns the ImageInfo describing the image.\n */\n getImageInfo(): ImageInfo;\n\n /**\n * Returns the backend texture of the image.\n * The returned object can be used to create a Skia Image object.\n * The returned object is backend specific and should be used with caution.\n * It is the caller's responsibility to ensure that the texture is not used after the image is deleted.\n * The returned object may be null if the image does not have a backend texture.\n *\n * @return backend texture of the image or null\n */\n getNativeTextureUnstable(): unknown;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param fm - The filter mode. (default nearest)\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps (default none)\n * calculated with makeCopyWithDefaultMipmaps;\n * @param localMatrix\n */\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param localMatrix\n */\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /** Encodes Image pixels, returning result as UInt8Array. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return Uint8Array with data\n */\n encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;\n\n /** Encodes Image pixels, returning result as a base64 encoded string. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return base64 encoded string of data\n */\n encodeToBase64(fmt?: ImageFormat, quality?: number): string;\n\n /** Read Image pixels\n *\n * @param srcX - optional x-axis upper left corner of the rectangle to read from\n * @param srcY - optional y-axis upper left corner of the rectangle to read from\n * @param imageInfo - optional describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX?: number,\n srcY?: number,\n imageInfo?: ImageInfo\n ): Float32Array | Uint8Array | null;\n\n /**\n * Returns raster image or lazy image. Copies SkImage backed by GPU texture\n * into CPU memory if needed. Returns original SkImage if decoded in raster\n * bitmap, or if encoded in a stream.\n * Returns null if the conversion fails.\n */\n makeNonTextureImage(): SkImage | null;\n}\n"],"mappings":";;;;;;IAiBYA,UAAU,GAAAC,OAAA,CAAAD,UAAA,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAAA,IAKVE,UAAU,GAAAD,OAAA,CAAAC,UAAA,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAAA,IAMVC,WAAW,GAAAF,OAAA,CAAAE,WAAA,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAQhB,MAAMC,eAAe,GAC1BC,QAAyB,IACM;EAC/B,SAAS;;EACT,OAAO,GAAG,IAAIA,QAAQ,IAAI,GAAG,IAAIA,QAAQ;AAC3C,CAAC;AAACJ,OAAA,CAAAG,eAAA,GAAAA,eAAA;AAEK,MAAME,qBAAqB,GAAAL,OAAA,CAAAK,qBAAA,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AACxD,MAAMC,uBAAuB,GAAAR,OAAA,CAAAQ,uBAAA,GAAG;EAAEF,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AACpD,MAAME,aAAa,GAAAT,OAAA,CAAAS,aAAA,GAAG;EAAEH,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE;AAAE,CAAC;AACpC,MAAMG,SAAS,GAAGA,CAACJ,CAAS,EAAEC,CAAS,MAAM;EAAED,CAAC;EAAEC;AAAE,CAAC,CAAC;AAACP,OAAA,CAAAU,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
|
-
import type { SkPicture, SkRect, SkSize } from "../skia/types";
|
|
2
|
+
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
|
|
3
3
|
export declare const isOnMainThread: () => boolean;
|
|
4
4
|
export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => Promise<SkPicture>;
|
|
5
|
-
export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<
|
|
6
|
-
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) =>
|
|
5
|
+
export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<SkImage | null>;
|
|
6
|
+
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) => SkImage | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Skia","Platform","SkiaSGRoot","isOnMainThread","_WORKLET","OS","drawAsPicture","element","bounds","recorder","PictureRecorder","canvas","beginRecording","root","render","drawOnCanvas","picture","finishRecordingAsPicture","dispose","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaSGRoot(Skia);\n await root.render(element);\n root.drawOnCanvas(canvas);\n const picture = recorder.finishRecordingAsPicture();\n recorder.dispose();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = async (element: ReactElement
|
|
1
|
+
{"version":3,"names":["Skia","Platform","SkiaSGRoot","isOnMainThread","_WORKLET","OS","drawAsPicture","element","bounds","recorder","PictureRecorder","canvas","beginRecording","root","render","drawOnCanvas","picture","finishRecordingAsPicture","dispose","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaSGRoot(Skia);\n await root.render(element);\n root.drawOnCanvas(canvas);\n const picture = recorder.finishRecordingAsPicture();\n recorder.dispose();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = async (\n element: ReactElement,\n size: SkSize\n): Promise<SkImage | null> => {\n return drawAsImageFromPicture(await drawAsPicture(element), size);\n};\n\nexport const drawAsImageFromPicture = (\n picture: SkPicture,\n size: SkSize\n): SkImage | null => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;\n const canvas = surface.getCanvas();\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n return image.makeNonTextureImage();\n};\n"],"mappings":"AAGA,SAASA,IAAI,QAAQ,SAAS;AAC9B,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,UAAU,QAAQ,oBAAoB;AAE/C,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDH,QAAQ,CAACI,EAAE,KAAK,KAAK;AAEzB,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG,MAAAA,CAAOC,OAAqB,EAAEC,MAAe,KAAK;EAC7E,MAAMC,QAAQ,GAAGT,IAAI,CAACU,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAc,CAACJ,MAAM,CAAC;EAC9C,MAAMK,IAAI,GAAG,IAAIX,UAAU,CAACF,IAAI,CAAC;EACjC,MAAMa,IAAI,CAACC,MAAM,CAACP,OAAO,CAAC;EAC1BM,IAAI,CAACE,YAAY,CAACJ,MAAM,CAAC;EACzB,MAAMK,OAAO,GAAGP,QAAQ,CAACQ,wBAAwB,CAAC,CAAC;EACnDR,QAAQ,CAACS,OAAO,CAAC,CAAC;EAClBL,IAAI,CAACM,OAAO,CAAC,CAAC;EACd,OAAOH,OAAO;AAChB,CAAC;AAED,OAAO,MAAMI,WAAW,GAAG,MAAAA,CACzBb,OAAqB,EACrBc,IAAY,KACgB;EAC5B,OAAOC,sBAAsB,CAAC,MAAMhB,aAAa,CAACC,OAAO,CAAC,EAAEc,IAAI,CAAC;AACnE,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAGA,CACpCN,OAAkB,EAClBK,IAAY,KACO;EACnB,SAAS;;EACT,MAAME,OAAO,GAAGvB,IAAI,CAACwB,OAAO,CAACC,aAAa,CAACJ,IAAI,CAACK,KAAK,EAAEL,IAAI,CAACM,MAAM,CAAE;EACpE,MAAMhB,MAAM,GAAGY,OAAO,CAACK,SAAS,CAAC,CAAC;EAClCjB,MAAM,CAACkB,WAAW,CAACb,OAAO,CAAC;EAC3BO,OAAO,CAACO,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGR,OAAO,CAACS,iBAAiB,CAAC,CAAC;EACzC,OAAOD,KAAK,CAACE,mBAAmB,CAAC,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
@@ -125,6 +125,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
|
125
125
|
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
|
126
126
|
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
|
127
127
|
* bitmap, or if encoded in a stream.
|
|
128
|
+
* Returns null if the conversion fails.
|
|
128
129
|
*/
|
|
129
|
-
makeNonTextureImage(): SkImage;
|
|
130
|
+
makeNonTextureImage(): SkImage | null;
|
|
130
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FilterMode","MipmapMode","ImageFormat","isCubicSampling","sampling","MitchellCubicSampling","B","C","CatmullRomCubicSampling","CubicSampling","MakeCubic"],"sources":["Image.ts"],"sourcesContent":["import type { SkMatrix } from \"../Matrix\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { TileMode } from \"../ImageFilter\";\nimport type { SkShader } from \"../Shader\";\n\nimport type { ImageInfo } from \"./ImageFactory\";\n\nexport interface CubicResampler {\n B: number;\n C: number;\n}\n\nexport interface FilterOptions {\n filter: FilterMode;\n mipmap?: MipmapMode;\n}\n\nexport enum FilterMode {\n Nearest,\n Linear,\n}\n\nexport enum MipmapMode {\n None,\n Nearest,\n Linear,\n}\n\nexport enum ImageFormat {\n JPEG = 3,\n PNG = 4,\n WEBP = 6,\n}\n\nexport type SamplingOptions = CubicResampler | FilterOptions;\n\nexport const isCubicSampling = (\n sampling: SamplingOptions\n): sampling is CubicResampler => {\n \"worklet\";\n return \"B\" in sampling && \"C\" in sampling;\n};\n\nexport const MitchellCubicSampling = { B: 1 / 3.0, C: 1 / 3.0 };\nexport const CatmullRomCubicSampling = { B: 0, C: 1 / 2.0 };\nexport const CubicSampling = { B: 0, C: 0 };\nexport const MakeCubic = (B: number, C: number) => ({ B, C });\n\nexport interface SkImage extends SkJSIInstance<\"Image\"> {\n /**\n * Returns the possibly scaled height of the image.\n */\n height(): number;\n\n /**\n * Returns the possibly scaled width of the image.\n */\n width(): number;\n\n /**\n * Returns the ImageInfo describing the image.\n */\n getImageInfo(): ImageInfo;\n\n /**\n * Returns the backend texture of the image.\n * The returned object can be used to create a Skia Image object.\n * The returned object is backend specific and should be used with caution.\n * It is the caller's responsibility to ensure that the texture is not used after the image is deleted.\n * The returned object may be null if the image does not have a backend texture.\n *\n * @return backend texture of the image or null\n */\n getNativeTextureUnstable(): unknown;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param fm - The filter mode. (default nearest)\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps (default none)\n * calculated with makeCopyWithDefaultMipmaps;\n * @param localMatrix\n */\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param localMatrix\n */\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /** Encodes Image pixels, returning result as UInt8Array. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return Uint8Array with data\n */\n encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;\n\n /** Encodes Image pixels, returning result as a base64 encoded string. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return base64 encoded string of data\n */\n encodeToBase64(fmt?: ImageFormat, quality?: number): string;\n\n /** Read Image pixels\n *\n * @param srcX - optional x-axis upper left corner of the rectangle to read from\n * @param srcY - optional y-axis upper left corner of the rectangle to read from\n * @param imageInfo - optional describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX?: number,\n srcY?: number,\n imageInfo?: ImageInfo\n ): Float32Array | Uint8Array | null;\n\n /**\n * Returns raster image or lazy image. Copies SkImage backed by GPU texture\n * into CPU memory if needed. Returns original SkImage if decoded in raster\n * bitmap, or if encoded in a stream.\n */\n makeNonTextureImage(): SkImage;\n}\n"],"mappings":"AAiBA,WAAYA,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAKtB,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAMtB,WAAYC,WAAW,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAQvB,OAAO,MAAMC,eAAe,GAC1BC,QAAyB,IACM;EAC/B,SAAS;;EACT,OAAO,GAAG,IAAIA,QAAQ,IAAI,GAAG,IAAIA,QAAQ;AAC3C,CAAC;AAED,OAAO,MAAMC,qBAAqB,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AAC/D,OAAO,MAAMC,uBAAuB,GAAG;EAAEF,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AAC3D,OAAO,MAAME,aAAa,GAAG;EAAEH,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE;AAAE,CAAC;AAC3C,OAAO,MAAMG,SAAS,GAAGA,CAACJ,CAAS,EAAEC,CAAS,MAAM;EAAED,CAAC;EAAEC;AAAE,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["FilterMode","MipmapMode","ImageFormat","isCubicSampling","sampling","MitchellCubicSampling","B","C","CatmullRomCubicSampling","CubicSampling","MakeCubic"],"sources":["Image.ts"],"sourcesContent":["import type { SkMatrix } from \"../Matrix\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { TileMode } from \"../ImageFilter\";\nimport type { SkShader } from \"../Shader\";\n\nimport type { ImageInfo } from \"./ImageFactory\";\n\nexport interface CubicResampler {\n B: number;\n C: number;\n}\n\nexport interface FilterOptions {\n filter: FilterMode;\n mipmap?: MipmapMode;\n}\n\nexport enum FilterMode {\n Nearest,\n Linear,\n}\n\nexport enum MipmapMode {\n None,\n Nearest,\n Linear,\n}\n\nexport enum ImageFormat {\n JPEG = 3,\n PNG = 4,\n WEBP = 6,\n}\n\nexport type SamplingOptions = CubicResampler | FilterOptions;\n\nexport const isCubicSampling = (\n sampling: SamplingOptions\n): sampling is CubicResampler => {\n \"worklet\";\n return \"B\" in sampling && \"C\" in sampling;\n};\n\nexport const MitchellCubicSampling = { B: 1 / 3.0, C: 1 / 3.0 };\nexport const CatmullRomCubicSampling = { B: 0, C: 1 / 2.0 };\nexport const CubicSampling = { B: 0, C: 0 };\nexport const MakeCubic = (B: number, C: number) => ({ B, C });\n\nexport interface SkImage extends SkJSIInstance<\"Image\"> {\n /**\n * Returns the possibly scaled height of the image.\n */\n height(): number;\n\n /**\n * Returns the possibly scaled width of the image.\n */\n width(): number;\n\n /**\n * Returns the ImageInfo describing the image.\n */\n getImageInfo(): ImageInfo;\n\n /**\n * Returns the backend texture of the image.\n * The returned object can be used to create a Skia Image object.\n * The returned object is backend specific and should be used with caution.\n * It is the caller's responsibility to ensure that the texture is not used after the image is deleted.\n * The returned object may be null if the image does not have a backend texture.\n *\n * @return backend texture of the image or null\n */\n getNativeTextureUnstable(): unknown;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param fm - The filter mode. (default nearest)\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps (default none)\n * calculated with makeCopyWithDefaultMipmaps;\n * @param localMatrix\n */\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /**\n * Returns this image as a shader with the specified tiling. It will use cubic sampling.\n * @param tx - tile mode in the x direction.\n * @param ty - tile mode in the y direction.\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param localMatrix\n */\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader;\n\n /** Encodes Image pixels, returning result as UInt8Array. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return Uint8Array with data\n */\n encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;\n\n /** Encodes Image pixels, returning result as a base64 encoded string. Returns existing\n encoded data if present; otherwise, SkImage is encoded with\n SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode\n SkImage.\n\n Returns nullptr if existing encoded data is missing or invalid, and\n encoding fails.\n\n @param fmt - PNG is the default value.\n @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.\n\n @return base64 encoded string of data\n */\n encodeToBase64(fmt?: ImageFormat, quality?: number): string;\n\n /** Read Image pixels\n *\n * @param srcX - optional x-axis upper left corner of the rectangle to read from\n * @param srcY - optional y-axis upper left corner of the rectangle to read from\n * @param imageInfo - optional describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX?: number,\n srcY?: number,\n imageInfo?: ImageInfo\n ): Float32Array | Uint8Array | null;\n\n /**\n * Returns raster image or lazy image. Copies SkImage backed by GPU texture\n * into CPU memory if needed. Returns original SkImage if decoded in raster\n * bitmap, or if encoded in a stream.\n * Returns null if the conversion fails.\n */\n makeNonTextureImage(): SkImage | null;\n}\n"],"mappings":"AAiBA,WAAYA,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAKtB,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAMtB,WAAYC,WAAW,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAQvB,OAAO,MAAMC,eAAe,GAC1BC,QAAyB,IACM;EAC/B,SAAS;;EACT,OAAO,GAAG,IAAIA,QAAQ,IAAI,GAAG,IAAIA,QAAQ;AAC3C,CAAC;AAED,OAAO,MAAMC,qBAAqB,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG,GAAG;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AAC/D,OAAO,MAAMC,uBAAuB,GAAG;EAAEF,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE,CAAC,GAAG;AAAI,CAAC;AAC3D,OAAO,MAAME,aAAa,GAAG;EAAEH,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE;AAAE,CAAC;AAC3C,OAAO,MAAMG,SAAS,GAAGA,CAACJ,CAAS,EAAEC,CAAS,MAAM;EAAED,CAAC;EAAEC;AAAE,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const __esModule: boolean;
|
|
2
2
|
export function isOnMainThread(): boolean;
|
|
3
3
|
export function drawAsPicture(element: any, bounds: any): Promise<import("../../..").SkPicture>;
|
|
4
|
-
export function drawAsImage(element: any, size: any): Promise<import("../../..").SkImage>;
|
|
5
|
-
export function drawAsImageFromPicture(picture: any, size: any): import("../../..").SkImage;
|
|
4
|
+
export function drawAsImage(element: any, size: any): Promise<import("../../..").SkImage | null>;
|
|
5
|
+
export function drawAsImageFromPicture(picture: any, size: any): import("../../..").SkImage | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export function isOnMainThread(): boolean;
|
|
2
2
|
export function drawAsPicture(element: any, bounds: any): Promise<import("../../..").SkPicture>;
|
|
3
|
-
export function drawAsImage(element: any, size: any): Promise<import("../../..").SkImage>;
|
|
4
|
-
export function drawAsImageFromPicture(picture: any, size: any): import("../../..").SkImage;
|
|
3
|
+
export function drawAsImage(element: any, size: any): Promise<import("../../..").SkImage | null>;
|
|
4
|
+
export function drawAsImageFromPicture(picture: any, size: any): import("../../..").SkImage | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
|
-
import type { SkPicture, SkRect, SkSize } from "../skia/types";
|
|
2
|
+
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
|
|
3
3
|
export declare const isOnMainThread: () => boolean;
|
|
4
4
|
export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => Promise<SkPicture>;
|
|
5
|
-
export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<
|
|
6
|
-
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) =>
|
|
5
|
+
export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<SkImage | null>;
|
|
6
|
+
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) => SkImage | null;
|
|
@@ -125,6 +125,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
|
125
125
|
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
|
126
126
|
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
|
127
127
|
* bitmap, or if encoded in a stream.
|
|
128
|
+
* Returns null if the conversion fails.
|
|
128
129
|
*/
|
|
129
|
-
makeNonTextureImage(): SkImage;
|
|
130
|
+
makeNonTextureImage(): SkImage | null;
|
|
130
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
2
|
|
|
3
|
-
import type { SkPicture, SkRect, SkSize } from "../skia/types";
|
|
3
|
+
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
|
|
4
4
|
import { Skia } from "../skia";
|
|
5
5
|
import { Platform } from "../Platform";
|
|
6
6
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
|
@@ -25,11 +25,17 @@ export const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {
|
|
|
25
25
|
return picture;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const drawAsImage = async (
|
|
28
|
+
export const drawAsImage = async (
|
|
29
|
+
element: ReactElement,
|
|
30
|
+
size: SkSize
|
|
31
|
+
): Promise<SkImage | null> => {
|
|
29
32
|
return drawAsImageFromPicture(await drawAsPicture(element), size);
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
export const drawAsImageFromPicture = (
|
|
35
|
+
export const drawAsImageFromPicture = (
|
|
36
|
+
picture: SkPicture,
|
|
37
|
+
size: SkSize
|
|
38
|
+
): SkImage | null => {
|
|
33
39
|
"worklet";
|
|
34
40
|
const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;
|
|
35
41
|
const canvas = surface.getCanvas();
|
|
@@ -153,6 +153,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
|
153
153
|
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
|
154
154
|
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
|
155
155
|
* bitmap, or if encoded in a stream.
|
|
156
|
+
* Returns null if the conversion fails.
|
|
156
157
|
*/
|
|
157
|
-
makeNonTextureImage(): SkImage;
|
|
158
|
+
makeNonTextureImage(): SkImage | null;
|
|
158
159
|
}
|