@shopify/react-native-skia 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +47 -21
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +8 -5
- package/apple/MetalWindowContext.mm +4 -2
- package/apple/RNSkApplePlatformContext.h +7 -5
- package/apple/RNSkApplePlatformContext.mm +30 -29
- package/apple/SkiaCVPixelBufferUtils.mm +4 -8
- package/apple/SkiaManager.mm +0 -3
- package/cpp/api/JsiSkImageFactory.h +14 -1
- package/cpp/api/JsiSkSurface.h +7 -1
- package/cpp/api/recorder/DrawingCtx.h +19 -2
- package/cpp/api/recorder/Paint.h +1 -3
- package/cpp/api/recorder/RNRecorder.h +5 -13
- package/cpp/rnskia/DawnContext.h +11 -2
- package/cpp/rnskia/DawnUtils.h +97 -6
- package/cpp/rnskia/DawnWindowContext.h +18 -11
- package/cpp/rnskia/RNSkJsiViewApi.h +91 -71
- package/cpp/rnskia/RNSkManager.cpp +3 -18
- package/cpp/rnskia/RNSkManager.h +0 -6
- package/cpp/rnskia/RNSkPlatformContext.h +22 -5
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +3 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +2 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js +4 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/sksg/HostConfig.js +1 -1
- package/lib/commonjs/sksg/HostConfig.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +14 -2
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +6 -2
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +3 -2
- package/lib/commonjs/sksg/Recorder/commands/Paint.js +5 -4
- package/lib/commonjs/sksg/Recorder/commands/Paint.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.js +4 -0
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -1
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +1 -1
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/module/skia/web/JsiSkImageFactory.js +3 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurface.d.ts +2 -1
- package/lib/module/skia/web/JsiSkSurface.js +4 -1
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/sksg/HostConfig.js +1 -1
- package/lib/module/sksg/HostConfig.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/module/sksg/Recorder/DrawingContext.js +14 -2
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +6 -2
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Paint.d.ts +3 -2
- package/lib/module/sksg/Recorder/commands/Paint.js +5 -4
- package/lib/module/sksg/Recorder/commands/Paint.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.js +4 -0
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/HostConfig.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +1 -1
- package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/HostConfig.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/module/sksg/Recorder/commands/Paint.d.ts +1 -1
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -1
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/src/sksg/Recorder/commands/Paint.d.ts +3 -2
- package/package.json +1 -1
- package/react-native-skia.podspec +43 -12
- package/src/renderer/__tests__/e2e/DataEncoding.spec.tsx +6 -2
- package/src/renderer/__tests__/e2e/Paint.spec.tsx +44 -1
- package/src/skia/types/Image/ImageFactory.ts +3 -1
- package/src/skia/types/Surface/Surface.ts +1 -1
- package/src/skia/web/JsiSkImageFactory.ts +4 -0
- package/src/skia/web/JsiSkSurface.ts +4 -1
- package/src/sksg/HostConfig.ts +2 -4
- package/src/sksg/Recorder/DrawingContext.ts +15 -1
- package/src/sksg/Recorder/Player.ts +6 -2
- package/src/sksg/Recorder/commands/Paint.ts +6 -5
- package/src/views/SkiaBaseWebView.tsx +4 -0
@@ -27,15 +27,7 @@ public:
|
|
27
27
|
wgpu::Surface surface, int width, int height)
|
28
28
|
: _recorder(recorder), _device(device), _surface(surface), _width(width),
|
29
29
|
_height(height) {
|
30
|
-
|
31
|
-
config.device = _device;
|
32
|
-
config.format = DawnUtils::PreferredTextureFormat;
|
33
|
-
config.width = _width;
|
34
|
-
config.height = _height;
|
35
|
-
#ifdef __APPLE__
|
36
|
-
config.alphaMode = wgpu::CompositeAlphaMode::Premultiplied;
|
37
|
-
#endif
|
38
|
-
_surface.Configure(&config);
|
30
|
+
configureSurface();
|
39
31
|
}
|
40
32
|
|
41
33
|
sk_sp<SkSurface> getSurface() override {
|
@@ -58,7 +50,9 @@ public:
|
|
58
50
|
void present() override;
|
59
51
|
|
60
52
|
void resize(int width, int height) override {
|
61
|
-
|
53
|
+
_width = width;
|
54
|
+
_height = height;
|
55
|
+
configureSurface();
|
62
56
|
}
|
63
57
|
|
64
58
|
int getWidth() override { return _width; }
|
@@ -66,6 +60,19 @@ public:
|
|
66
60
|
int getHeight() override { return _height; }
|
67
61
|
|
68
62
|
private:
|
63
|
+
void configureSurface() {
|
64
|
+
wgpu::SurfaceConfiguration config;
|
65
|
+
config.device = _device;
|
66
|
+
config.format = DawnUtils::PreferredTextureFormat;
|
67
|
+
config.width = _width;
|
68
|
+
config.height = _height;
|
69
|
+
config.presentMode = wgpu::PresentMode::Fifo;
|
70
|
+
#ifdef __APPLE__
|
71
|
+
config.alphaMode = wgpu::CompositeAlphaMode::Premultiplied;
|
72
|
+
#endif
|
73
|
+
_surface.Configure(&config);
|
74
|
+
}
|
75
|
+
|
69
76
|
skgpu::graphite::Recorder *_recorder;
|
70
77
|
// TODO: keep device in DawnContext? Do we need it for resizing?
|
71
78
|
wgpu::Device _device;
|
@@ -74,4 +81,4 @@ private:
|
|
74
81
|
int _height;
|
75
82
|
};
|
76
83
|
|
77
|
-
} // namespace RNSkia
|
84
|
+
} // namespace RNSkia
|
@@ -3,6 +3,7 @@
|
|
3
3
|
#include <functional>
|
4
4
|
#include <memory>
|
5
5
|
#include <mutex>
|
6
|
+
#include <shared_mutex>
|
6
7
|
#include <string>
|
7
8
|
#include <unordered_map>
|
8
9
|
#include <utility>
|
@@ -23,6 +24,47 @@ using RNSkViewInfo = struct RNSkViewInfo {
|
|
23
24
|
std::unordered_map<std::string, RNJsi::ViewProperty> props;
|
24
25
|
};
|
25
26
|
|
27
|
+
class ViewRegistry {
|
28
|
+
public:
|
29
|
+
static ViewRegistry &getInstance() {
|
30
|
+
static ViewRegistry instance;
|
31
|
+
return instance;
|
32
|
+
}
|
33
|
+
|
34
|
+
ViewRegistry(const ViewRegistry &) = delete;
|
35
|
+
ViewRegistry &operator=(const ViewRegistry &) = delete;
|
36
|
+
|
37
|
+
void removeViewInfo(size_t id) {
|
38
|
+
std::unique_lock<std::shared_mutex> lock(_mutex);
|
39
|
+
_registry.erase(id);
|
40
|
+
}
|
41
|
+
|
42
|
+
// Execute a function while holding the registry lock
|
43
|
+
template<typename F>
|
44
|
+
auto withViewInfo(size_t id, F&& func) -> decltype(func(std::shared_ptr<RNSkViewInfo>())) {
|
45
|
+
std::unique_lock<std::shared_mutex> lock(_mutex);
|
46
|
+
auto it = _registry.find(id);
|
47
|
+
std::shared_ptr<RNSkViewInfo> info;
|
48
|
+
if (it != _registry.end()) {
|
49
|
+
info = it->second;
|
50
|
+
} else {
|
51
|
+
info = std::make_shared<RNSkViewInfo>();
|
52
|
+
_registry[id] = info;
|
53
|
+
}
|
54
|
+
return func(info);
|
55
|
+
}
|
56
|
+
|
57
|
+
void clear() {
|
58
|
+
std::unique_lock<std::shared_mutex> lock(_mutex);
|
59
|
+
_registry.clear();
|
60
|
+
}
|
61
|
+
|
62
|
+
private:
|
63
|
+
ViewRegistry() = default;
|
64
|
+
mutable std::shared_mutex _mutex;
|
65
|
+
std::unordered_map<size_t, std::shared_ptr<RNSkViewInfo>> _registry;
|
66
|
+
};
|
67
|
+
|
26
68
|
class RNSkJsiViewApi : public RNJsi::JsiHostObject,
|
27
69
|
public std::enable_shared_from_this<RNSkJsiViewApi> {
|
28
70
|
public:
|
@@ -53,19 +95,21 @@ public:
|
|
53
95
|
}
|
54
96
|
|
55
97
|
auto nativeId = arguments[0].asNumber();
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
98
|
+
|
99
|
+
// Safely execute operations while holding the registry lock
|
100
|
+
ViewRegistry::getInstance().withViewInfo(nativeId, [&](std::shared_ptr<RNSkViewInfo> info) {
|
101
|
+
info->props.insert_or_assign(arguments[1].asString(runtime).utf8(runtime),
|
102
|
+
RNJsi::ViewProperty(runtime, arguments[2]));
|
103
|
+
|
104
|
+
// Now let's see if we have a view that we can update
|
105
|
+
if (info->view != nullptr) {
|
106
|
+
// Update view!
|
107
|
+
info->view->setNativeId(nativeId);
|
108
|
+
info->view->setJsiProperties(info->props);
|
109
|
+
info->props.clear();
|
110
|
+
}
|
111
|
+
return nullptr; // Return type for template deduction
|
112
|
+
});
|
69
113
|
|
70
114
|
return jsi::Value::undefined();
|
71
115
|
}
|
@@ -88,11 +132,12 @@ public:
|
|
88
132
|
|
89
133
|
// find Skia View
|
90
134
|
int nativeId = arguments[0].asNumber();
|
91
|
-
std::
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
135
|
+
ViewRegistry::getInstance().withViewInfo(nativeId, [](std::shared_ptr<RNSkViewInfo> info) {
|
136
|
+
if (info->view != nullptr) {
|
137
|
+
info->view->requestRedraw();
|
138
|
+
}
|
139
|
+
return nullptr;
|
140
|
+
});
|
96
141
|
return jsi::Value::undefined();
|
97
142
|
}
|
98
143
|
|
@@ -113,12 +158,10 @@ public:
|
|
113
158
|
// find Skia view
|
114
159
|
int nativeId = arguments[0].asNumber();
|
115
160
|
sk_sp<SkImage> image;
|
116
|
-
std::shared_ptr<RNSkView> view
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
view = info->view;
|
121
|
-
}
|
161
|
+
std::shared_ptr<RNSkView> view = ViewRegistry::getInstance().withViewInfo(nativeId,
|
162
|
+
[](std::shared_ptr<RNSkViewInfo> info) {
|
163
|
+
return info->view;
|
164
|
+
});
|
122
165
|
if (view != nullptr) {
|
123
166
|
if (count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()) {
|
124
167
|
auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
|
@@ -154,12 +197,10 @@ public:
|
|
154
197
|
|
155
198
|
// find Skia view
|
156
199
|
int nativeId = arguments[0].asNumber();
|
157
|
-
std::shared_ptr<RNSkView> view
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
view = info->view;
|
162
|
-
}
|
200
|
+
std::shared_ptr<RNSkView> view = ViewRegistry::getInstance().withViewInfo(nativeId,
|
201
|
+
[](std::shared_ptr<RNSkViewInfo> info) {
|
202
|
+
return info->view;
|
203
|
+
});
|
163
204
|
auto context = _platformContext;
|
164
205
|
auto bounds =
|
165
206
|
count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()
|
@@ -205,8 +246,7 @@ public:
|
|
205
246
|
Call to remove all draw view infos
|
206
247
|
*/
|
207
248
|
void unregisterAll() {
|
208
|
-
|
209
|
-
_viewInfos.clear();
|
249
|
+
ViewRegistry::getInstance().clear();
|
210
250
|
}
|
211
251
|
|
212
252
|
/**
|
@@ -215,12 +255,13 @@ public:
|
|
215
255
|
* @param view View to register
|
216
256
|
*/
|
217
257
|
void registerSkiaView(size_t nativeId, std::shared_ptr<RNSkView> view) {
|
218
|
-
std::
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
258
|
+
ViewRegistry::getInstance().withViewInfo(nativeId, [&](std::shared_ptr<RNSkViewInfo> info) {
|
259
|
+
info->view = view;
|
260
|
+
info->view->setNativeId(nativeId);
|
261
|
+
info->view->setJsiProperties(info->props);
|
262
|
+
info->props.clear();
|
263
|
+
return nullptr;
|
264
|
+
});
|
224
265
|
}
|
225
266
|
|
226
267
|
/**
|
@@ -228,14 +269,7 @@ public:
|
|
228
269
|
* @param nativeId View id
|
229
270
|
*/
|
230
271
|
void unregisterSkiaView(size_t nativeId) {
|
231
|
-
|
232
|
-
if (_viewInfos.count(nativeId) == 0) {
|
233
|
-
return;
|
234
|
-
}
|
235
|
-
auto info = getEnsuredViewInfo(nativeId);
|
236
|
-
|
237
|
-
info->view = nullptr;
|
238
|
-
_viewInfos.erase(nativeId);
|
272
|
+
ViewRegistry::getInstance().removeViewInfo(nativeId);
|
239
273
|
}
|
240
274
|
|
241
275
|
/**
|
@@ -245,34 +279,20 @@ public:
|
|
245
279
|
or a valid view, effectively toggling the view's availability.
|
246
280
|
*/
|
247
281
|
void setSkiaView(size_t nativeId, std::shared_ptr<RNSkView> view) {
|
248
|
-
std::
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
282
|
+
ViewRegistry::getInstance().withViewInfo(nativeId, [&](std::shared_ptr<RNSkViewInfo> info) {
|
283
|
+
if (view != nullptr) {
|
284
|
+
info->view = view;
|
285
|
+
info->view->setNativeId(nativeId);
|
286
|
+
info->view->setJsiProperties(info->props);
|
287
|
+
info->props.clear();
|
288
|
+
} else {
|
289
|
+
info->view = view; // Set to nullptr
|
290
|
+
}
|
291
|
+
return nullptr;
|
292
|
+
});
|
258
293
|
}
|
259
294
|
|
260
295
|
private:
|
261
|
-
/**
|
262
|
-
* Creates or returns the callback info object for the given view
|
263
|
-
* @param nativeId View id
|
264
|
-
* @return The callback info object for the requested view
|
265
|
-
*/
|
266
|
-
RNSkViewInfo *getEnsuredViewInfo(size_t nativeId) {
|
267
|
-
if (_viewInfos.count(nativeId) == 0) {
|
268
|
-
RNSkViewInfo info;
|
269
|
-
_viewInfos.emplace(nativeId, info);
|
270
|
-
}
|
271
|
-
return &_viewInfos.at(nativeId);
|
272
|
-
}
|
273
|
-
|
274
|
-
std::unordered_map<size_t, RNSkViewInfo> _viewInfos;
|
275
296
|
std::shared_ptr<RNSkPlatformContext> _platformContext;
|
276
|
-
std::mutex _mutex;
|
277
297
|
};
|
278
298
|
} // namespace RNSkia
|
@@ -30,7 +30,6 @@ RNSkManager::RNSkManager(
|
|
30
30
|
}
|
31
31
|
|
32
32
|
RNSkManager::~RNSkManager() {
|
33
|
-
invalidate();
|
34
33
|
// Free up any references
|
35
34
|
_viewApi = nullptr;
|
36
35
|
_jsRuntime = nullptr;
|
@@ -38,36 +37,22 @@ RNSkManager::~RNSkManager() {
|
|
38
37
|
_jsCallInvoker = nullptr;
|
39
38
|
}
|
40
39
|
|
41
|
-
void RNSkManager::invalidate() {
|
42
|
-
if (_isInvalidated) {
|
43
|
-
return;
|
44
|
-
}
|
45
|
-
_isInvalidated = true;
|
46
|
-
|
47
|
-
// Invalidate members
|
48
|
-
_viewApi->unregisterAll();
|
49
|
-
}
|
50
|
-
|
51
40
|
void RNSkManager::registerSkiaView(size_t nativeId,
|
52
41
|
std::shared_ptr<RNSkView> view) {
|
53
|
-
|
54
|
-
_viewApi->registerSkiaView(nativeId, std::move(view));
|
42
|
+
_viewApi->registerSkiaView(nativeId, std::move(view));
|
55
43
|
}
|
56
44
|
|
57
45
|
void RNSkManager::unregisterSkiaView(size_t nativeId) {
|
58
|
-
|
59
|
-
_viewApi->unregisterSkiaView(nativeId);
|
46
|
+
_viewApi->unregisterSkiaView(nativeId);
|
60
47
|
}
|
61
48
|
|
62
49
|
void RNSkManager::setSkiaView(size_t nativeId, std::shared_ptr<RNSkView> view) {
|
63
|
-
|
64
|
-
_viewApi->setSkiaView(nativeId, std::move(view));
|
50
|
+
_viewApi->setSkiaView(nativeId, std::move(view));
|
65
51
|
}
|
66
52
|
|
67
53
|
void RNSkManager::installBindings() {
|
68
54
|
// Create the API objects and install it on the global object in the
|
69
55
|
// provided runtime.
|
70
|
-
|
71
56
|
auto skiaApi = std::make_shared<JsiSkApi>(_platformContext);
|
72
57
|
_jsRuntime->global().setProperty(
|
73
58
|
*_jsRuntime, "SkiaApi",
|
package/cpp/rnskia/RNSkManager.h
CHANGED
@@ -33,11 +33,6 @@ public:
|
|
33
33
|
|
34
34
|
~RNSkManager();
|
35
35
|
|
36
|
-
/**
|
37
|
-
Invalidates the Skia Manager
|
38
|
-
*/
|
39
|
-
void invalidate();
|
40
|
-
|
41
36
|
/**
|
42
37
|
* Registers a RNSkView with the given native id
|
43
38
|
* @param nativeId Native view id
|
@@ -77,7 +72,6 @@ private:
|
|
77
72
|
std::shared_ptr<RNSkPlatformContext> _platformContext;
|
78
73
|
std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
|
79
74
|
std::shared_ptr<RNSkJsiViewApi> _viewApi;
|
80
|
-
std::atomic<bool> _isInvalidated = {false};
|
81
75
|
};
|
82
76
|
|
83
77
|
} // namespace RNSkia
|
@@ -105,22 +105,39 @@ public:
|
|
105
105
|
*/
|
106
106
|
virtual sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) = 0;
|
107
107
|
|
108
|
+
#if !defined(SK_GRAPHITE)
|
108
109
|
virtual sk_sp<SkImage>
|
109
110
|
makeImageFromNativeTexture(const TextureInfo &textureInfo, int width,
|
110
111
|
int height, bool mipMapped) = 0;
|
111
112
|
|
112
|
-
|
113
|
+
virtual const TextureInfo getTexture(sk_sp<SkSurface> image) = 0;
|
114
|
+
|
115
|
+
virtual const TextureInfo getTexture(sk_sp<SkImage> image) = 0;
|
116
|
+
|
113
117
|
virtual GrDirectContext *getDirectContext() = 0;
|
118
|
+
#else
|
119
|
+
sk_sp<SkImage> makeImageFromNativeTexture(const TextureInfo &textureInfo,
|
120
|
+
int width, int height,
|
121
|
+
bool mipMapped) {
|
122
|
+
throw std::runtime_error(
|
123
|
+
"makeImageFromNativeTexture not implemented yet on Graphite");
|
124
|
+
}
|
125
|
+
|
126
|
+
const TextureInfo getTexture(sk_sp<SkSurface> image) {
|
127
|
+
throw std::runtime_error(
|
128
|
+
"getTexture(surface) not implemented yet on Graphite");
|
129
|
+
}
|
130
|
+
|
131
|
+
const TextureInfo getTexture(sk_sp<SkImage> image) {
|
132
|
+
throw std::runtime_error(
|
133
|
+
"getTexture(image) not implemented yet on Graphite");
|
134
|
+
}
|
114
135
|
#endif
|
115
136
|
|
116
137
|
virtual void releaseNativeBuffer(uint64_t pointer) = 0;
|
117
138
|
|
118
139
|
virtual uint64_t makeNativeBuffer(sk_sp<SkImage> image) = 0;
|
119
140
|
|
120
|
-
virtual const TextureInfo getTexture(sk_sp<SkSurface> image) = 0;
|
121
|
-
|
122
|
-
virtual const TextureInfo getTexture(sk_sp<SkImage> image) = 0;
|
123
|
-
|
124
141
|
virtual std::shared_ptr<RNSkVideo> createVideo(const std::string &url) = 0;
|
125
142
|
|
126
143
|
/**
|
@@ -15,6 +15,7 @@ export interface ImageInfo {
|
|
15
15
|
width: number;
|
16
16
|
}
|
17
17
|
export interface ImageFactory {
|
18
|
+
MakeNull: () => SkImage;
|
18
19
|
/**
|
19
20
|
* Return an Image backed by the encoded data, but attempt to defer decoding until the image
|
20
21
|
* is actually used/drawn. This deferral allows the system to cache the result, either on the
|
@@ -58,7 +59,7 @@ export interface ImageFactory {
|
|
58
59
|
*
|
59
60
|
* @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.
|
60
61
|
*/
|
61
|
-
MakeImageFromNativeTextureUnstable: (texture: unknown, width: number, height: number, mipmapped?: boolean) => SkImage;
|
62
|
+
MakeImageFromNativeTextureUnstable: (texture: unknown, width: number, height: number, mipmapped?: boolean, outputImage?: SkImage) => SkImage;
|
62
63
|
/**
|
63
64
|
* Returns an image that will be a screenshot of the view represented by
|
64
65
|
* the view tag
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["AlphaType","exports"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { ColorType } from \"./ColorType\";\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Return an Image backed by a given native buffer.\n * The native buffer must be a valid owning reference.\n *\n * For instance, this API is used by\n * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)\n * to render a Skia Camera preview.\n *\n * - On Android; This is an `AHardwareBuffer*`\n * - On iOS, this is a `CVPixelBufferRef`\n * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * native buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;\n\n /**\n *\n * Return an Image backed by a given native texture.\n *\n * The native texture must be a valid owning reference.\n *\n * This API might be used to integrate with other libraries using gpu textures,\n * or to transfer images between different threads.\n *\n * @param texture A native texture handle\n * @param width The width of the texture\n * @param height The height of the texture\n * @param mipmapped Whether the texture is mipmapped\n * @throws Throws an error if the Image could not be created, for example when the given native texture is invalid.\n *\n * @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.\n */\n MakeImageFromNativeTextureUnstable: (\n texture: unknown,\n width: number,\n height: number,\n mipmapped?: boolean\n ) => SkImage;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n}\n"],"mappings":";;;;;;IAMYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA","ignoreList":[]}
|
1
|
+
{"version":3,"names":["AlphaType","exports"],"sources":["ImageFactory.ts"],"sourcesContent":["import type { SkData } from \"../Data\";\nimport type { NativeBuffer } from \"../NativeBuffer\";\n\nimport type { ColorType } from \"./ColorType\";\nimport type { SkImage } from \"./Image\";\n\nexport enum AlphaType {\n Unknown,\n Opaque,\n Premul,\n Unpremul,\n}\n\nexport interface ImageInfo {\n alphaType: AlphaType;\n // TODO: add support for color space\n // colorSpace: ColorSpace;\n colorType: ColorType;\n height: number;\n width: number;\n}\n\nexport interface ImageFactory {\n MakeNull: () => SkImage;\n /**\n * Return an Image backed by the encoded data, but attempt to defer decoding until the image\n * is actually used/drawn. This deferral allows the system to cache the result, either on the\n * CPU or on the GPU, depending on where the image is drawn.\n * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are\n * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.\n * @param data - Data object with bytes of data\n * @returns If the encoded format is not supported, or subset is outside of the bounds of the decoded\n * image, nullptr is returned.\n */\n MakeImageFromEncoded: (encoded: SkData) => SkImage | null;\n\n /**\n * Return an Image backed by a given native buffer.\n * The native buffer must be a valid owning reference.\n *\n * For instance, this API is used by\n * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)\n * to render a Skia Camera preview.\n *\n * - On Android; This is an `AHardwareBuffer*`\n * - On iOS, this is a `CVPixelBufferRef`\n * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer\n * @throws Throws an error if the Image could not be created, for example when the given\n * native buffer is invalid.\n */\n MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;\n\n /**\n *\n * Return an Image backed by a given native texture.\n *\n * The native texture must be a valid owning reference.\n *\n * This API might be used to integrate with other libraries using gpu textures,\n * or to transfer images between different threads.\n *\n * @param texture A native texture handle\n * @param width The width of the texture\n * @param height The height of the texture\n * @param mipmapped Whether the texture is mipmapped\n * @throws Throws an error if the Image could not be created, for example when the given native texture is invalid.\n *\n * @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.\n */\n MakeImageFromNativeTextureUnstable: (\n texture: unknown,\n width: number,\n height: number,\n mipmapped?: boolean,\n outputImage?: SkImage\n ) => SkImage;\n\n /**\n * Returns an image that will be a screenshot of the view represented by\n * the view tag\n * @param viewTag - The tag of the view to make an image from.\n * @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.\n */\n MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;\n\n /**\n * Returns an image with the given pixel data and format.\n * Note that we will always make a copy of the pixel data, because of inconsistencies in\n * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and\n * not modifiable after creation).\n *\n * @param info\n * @param data - bytes representing the pixel data.\n * @param bytesPerRow\n */\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;\n}\n"],"mappings":";;;;;;IAMYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA","ignoreList":[]}
|
@@ -32,7 +32,7 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
32
32
|
|
33
33
|
example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot
|
34
34
|
*/
|
35
|
-
makeImageSnapshot(bounds?: SkRect): SkImage;
|
35
|
+
makeImageSnapshot(bounds?: SkRect, outputImage?: SkImage): SkImage;
|
36
36
|
/**
|
37
37
|
* Make sure any queued draws are sent to the screen or the GPU.
|
38
38
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["Surface.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkCanvas } from \"../Canvas\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkRect } from \"../Rect\";\n\nexport interface SkSurface extends SkJSIInstance<\"Surface\"> {\n /** Returns Canvas that draws into the surface. Subsequent calls return the\n same Canvas. Canvas returned is managed and owned by Surface, and is\n deleted when Surface is deleted.\n\n @return drawing Canvas for Surface\n\n example: https://fiddle.skia.org/c/@Surface_getCanvas\n */\n getCanvas(): SkCanvas;\n\n /**\n * Returns the backend texture of the surface.\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 surface is deleted\n * or draw operations are performed on the surface.\n * The returned object may be null if the surface does not have a backend texture.\n *\n * @return backend texture of the surface or null\n */\n getNativeTextureUnstable(): unknown;\n\n /** Returns Image capturing Surface contents. Subsequent drawing to\n Surface contents are not captured.\n\n @param bounds A rectangle specifying the subset of the surface that\n is of interest.\n @return Image initialized with Surface contents\n\n example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot\n */\n makeImageSnapshot(bounds?: SkRect): SkImage;\n\n /**\n * Make sure any queued draws are sent to the screen or the GPU.\n */\n flush(): void;\n\n /**\n * Returns the possibly scaled width of the surface.\n */\n width(): number;\n\n /**\n * Returns the possibly scaled height of the surface.\n */\n height(): number;\n}\n"],"mappings":"","ignoreList":[]}
|
1
|
+
{"version":3,"names":[],"sources":["Surface.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkCanvas } from \"../Canvas\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkRect } from \"../Rect\";\n\nexport interface SkSurface extends SkJSIInstance<\"Surface\"> {\n /** Returns Canvas that draws into the surface. Subsequent calls return the\n same Canvas. Canvas returned is managed and owned by Surface, and is\n deleted when Surface is deleted.\n\n @return drawing Canvas for Surface\n\n example: https://fiddle.skia.org/c/@Surface_getCanvas\n */\n getCanvas(): SkCanvas;\n\n /**\n * Returns the backend texture of the surface.\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 surface is deleted\n * or draw operations are performed on the surface.\n * The returned object may be null if the surface does not have a backend texture.\n *\n * @return backend texture of the surface or null\n */\n getNativeTextureUnstable(): unknown;\n\n /** Returns Image capturing Surface contents. Subsequent drawing to\n Surface contents are not captured.\n\n @param bounds A rectangle specifying the subset of the surface that\n is of interest.\n @return Image initialized with Surface contents\n\n example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot\n */\n makeImageSnapshot(bounds?: SkRect, outputImage?: SkImage): SkImage;\n\n /**\n * Make sure any queued draws are sent to the screen or the GPU.\n */\n flush(): void;\n\n /**\n * Returns the possibly scaled width of the surface.\n */\n width(): number;\n\n /**\n * Returns the possibly scaled height of the surface.\n */\n height(): number;\n}\n"],"mappings":"","ignoreList":[]}
|
@@ -5,6 +5,7 @@ import { JsiSkImage } from "./JsiSkImage";
|
|
5
5
|
import type { JsiSkSurface } from "./JsiSkSurface";
|
6
6
|
export declare class JsiSkImageFactory extends Host implements ImageFactory {
|
7
7
|
constructor(CanvasKit: CanvasKit);
|
8
|
+
MakeNull(): JsiSkImage;
|
8
9
|
MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
|
9
10
|
MakeImageFromNativeBuffer(buffer: NativeBuffer, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
|
10
11
|
MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
|
@@ -12,6 +12,9 @@ class JsiSkImageFactory extends _Host.Host {
|
|
12
12
|
constructor(CanvasKit) {
|
13
13
|
super(CanvasKit);
|
14
14
|
}
|
15
|
+
MakeNull() {
|
16
|
+
return new _JsiSkImage.JsiSkImage(this.CanvasKit, null);
|
17
|
+
}
|
15
18
|
MakeImageFromViewTag(viewTag) {
|
16
19
|
const view = viewTag;
|
17
20
|
// TODO: Implement screenshot from view in React JS
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_types","require","_Host","_JsiSkImage","_JsiSkData","JsiSkImageFactory","Host","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromNativeBuffer","buffer","surface","image","isNativeBufferWeb","Error","img","HTMLImageElement","HTMLVideoElement","ImageBitmap","MakeLazyImageFromTextureSource","CanvasKitWebGLBuffer","toImage","MakeImageFromCanvasImageSource","
|
1
|
+
{"version":3,"names":["_types","require","_Host","_JsiSkImage","_JsiSkData","JsiSkImageFactory","Host","constructor","CanvasKit","MakeNull","JsiSkImage","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromNativeBuffer","buffer","surface","image","isNativeBufferWeb","Error","img","HTMLImageElement","HTMLVideoElement","ImageBitmap","MakeLazyImageFromTextureSource","CanvasKitWebGLBuffer","toImage","MakeImageFromCanvasImageSource","makeImageFromTextureSource","updateTextureFromSource","MakeImageFromEncoded","encoded","JsiSkData","fromValue","MakeImageFromNativeTextureUnstable","throwNotImplementedOnRNWeb","MakeImage","info","data","bytesPerRow","alphaType","getEnum","colorSpace","ColorSpace","SRGB","colorType","height","width","exports"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit, Image } from \"canvaskit-wasm\";\n\nimport { CanvasKitWebGLBuffer, isNativeBufferWeb } from \"../types\";\nimport type {\n SkData,\n ImageInfo,\n SkImage,\n NativeBuffer,\n ImageFactory,\n} from \"../types\";\n\nimport { Host, getEnum, throwNotImplementedOnRNWeb } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\nimport type { JsiSkSurface } from \"./JsiSkSurface\";\nimport type { CanvasKitWebGLBufferImpl } from \"./CanvasKitWebGLBufferImpl\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeNull() {\n return new JsiSkImage(this.CanvasKit, null as unknown as Image);\n }\n\n MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {\n const view = viewTag as unknown as HTMLElement;\n // TODO: Implement screenshot from view in React JS\n console.log(view);\n return Promise.resolve(null);\n }\n\n MakeImageFromNativeBuffer(\n buffer: NativeBuffer,\n surface?: JsiSkSurface,\n image?: JsiSkImage\n ) {\n if (!isNativeBufferWeb(buffer)) {\n throw new Error(\"Invalid NativeBuffer\");\n }\n if (!surface) {\n let img: Image;\n if (\n buffer instanceof HTMLImageElement ||\n buffer instanceof HTMLVideoElement ||\n buffer instanceof ImageBitmap\n ) {\n img = this.CanvasKit.MakeLazyImageFromTextureSource(buffer);\n } else if (buffer instanceof CanvasKitWebGLBuffer) {\n img = (\n buffer as CanvasKitWebGLBuffer as CanvasKitWebGLBufferImpl\n ).toImage();\n } else {\n img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);\n }\n return new JsiSkImage(this.CanvasKit, img);\n } else if (!image) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).makeImageFromTextureSource(buffer) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).updateTextureFromSource(\n image,\n buffer\n ) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n }\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImageFromNativeTextureUnstable() {\n return throwNotImplementedOnRNWeb<SkImage>();\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: getEnum(this.CanvasKit, \"AlphaType\", info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: getEnum(this.CanvasKit, \"ColorType\", info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":"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","ignoreList":[]}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { CanvasKit, Surface } from "canvaskit-wasm";
|
2
2
|
import type { SkCanvas, SkImage, SkRect, SkSurface } from "../types";
|
3
3
|
import { HostObject } from "./Host";
|
4
|
+
import { JsiSkImage } from "./JsiSkImage";
|
4
5
|
export declare class JsiSkSurface extends HostObject<Surface, "Surface"> implements SkSurface {
|
5
6
|
constructor(CanvasKit: CanvasKit, ref: Surface);
|
6
7
|
dispose: () => void;
|
@@ -8,6 +9,6 @@ export declare class JsiSkSurface extends HostObject<Surface, "Surface"> impleme
|
|
8
9
|
width(): number;
|
9
10
|
height(): number;
|
10
11
|
getCanvas(): SkCanvas;
|
11
|
-
makeImageSnapshot(bounds?: SkRect): SkImage;
|
12
|
+
makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage;
|
12
13
|
getNativeTextureUnstable(): unknown;
|
13
14
|
}
|
@@ -30,8 +30,11 @@ class JsiSkSurface extends _Host.HostObject {
|
|
30
30
|
getCanvas() {
|
31
31
|
return new _JsiSkCanvas.JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());
|
32
32
|
}
|
33
|
-
makeImageSnapshot(bounds) {
|
33
|
+
makeImageSnapshot(bounds, outputImage) {
|
34
34
|
const image = this.ref.makeImageSnapshot(bounds ? Array.from(_JsiSkRect.JsiSkRect.fromValue(this.CanvasKit, bounds)) : undefined);
|
35
|
+
if (outputImage) {
|
36
|
+
outputImage.ref = image;
|
37
|
+
}
|
35
38
|
return new _JsiSkImage.JsiSkImage(this.CanvasKit, image);
|
36
39
|
}
|
37
40
|
getNativeTextureUnstable() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_Host","require","_JsiSkCanvas","_JsiSkImage","_JsiSkRect","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","JsiSkSurface","HostObject","constructor","CanvasKit","ref","dispose","flush","width","height","getCanvas","JsiSkCanvas","makeImageSnapshot","bounds","image","Array","from","JsiSkRect","fromValue","undefined","JsiSkImage","getNativeTextureUnstable","console","warn","exports"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n dispose = () => {\n this.ref.dispose();\n };\n\n flush() {\n this.ref.flush();\n }\n\n width() {\n return this.ref.width();\n }\n\n height() {\n return this.ref.height();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n getNativeTextureUnstable(): unknown {\n console.warn(\"getBackendTexture is not implemented on Web\");\n return null;\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAAwC,SAAAI,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA;AAEjC,MAAMgB,YAAY,SACfC,gBAAU,CAEpB;EACEC,WAAWA,CAACC,SAAoB,EAAEC,GAAY,EAAE;IAC9C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;IAACvB,eAAA,kBAGzB,MAAM;MACd,IAAI,CAACuB,GAAG,CAACC,OAAO,CAAC,CAAC;IACpB,CAAC;EAJD;EAMAC,KAAKA,CAAA,EAAG;IACN,IAAI,CAACF,GAAG,CAACE,KAAK,CAAC,CAAC;EAClB;EAEAC,KAAKA,CAAA,EAAG;IACN,OAAO,IAAI,CAACH,GAAG,CAACG,KAAK,CAAC,CAAC;EACzB;EAEAC,MAAMA,CAAA,EAAG;IACP,OAAO,IAAI,CAACJ,GAAG,CAACI,MAAM,CAAC,CAAC;EAC1B;EAEAC,SAASA,CAAA,EAAa;IACpB,OAAO,IAAIC,wBAAW,CAAC,IAAI,CAACP,SAAS,EAAE,IAAI,CAACC,GAAG,CAACK,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAE,iBAAiBA,CAACC,MAAe,EAAW;
|
1
|
+
{"version":3,"names":["_Host","require","_JsiSkCanvas","_JsiSkImage","_JsiSkRect","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","JsiSkSurface","HostObject","constructor","CanvasKit","ref","dispose","flush","width","height","getCanvas","JsiSkCanvas","makeImageSnapshot","bounds","outputImage","image","Array","from","JsiSkRect","fromValue","undefined","JsiSkImage","getNativeTextureUnstable","console","warn","exports"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n dispose = () => {\n this.ref.dispose();\n };\n\n flush() {\n this.ref.flush();\n }\n\n width() {\n return this.ref.width();\n }\n\n height() {\n return this.ref.height();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n if (outputImage) {\n outputImage.ref = image;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n getNativeTextureUnstable(): unknown {\n console.warn(\"getBackendTexture is not implemented on Web\");\n return null;\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAAwC,SAAAI,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA;AAEjC,MAAMgB,YAAY,SACfC,gBAAU,CAEpB;EACEC,WAAWA,CAACC,SAAoB,EAAEC,GAAY,EAAE;IAC9C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;IAACvB,eAAA,kBAGzB,MAAM;MACd,IAAI,CAACuB,GAAG,CAACC,OAAO,CAAC,CAAC;IACpB,CAAC;EAJD;EAMAC,KAAKA,CAAA,EAAG;IACN,IAAI,CAACF,GAAG,CAACE,KAAK,CAAC,CAAC;EAClB;EAEAC,KAAKA,CAAA,EAAG;IACN,OAAO,IAAI,CAACH,GAAG,CAACG,KAAK,CAAC,CAAC;EACzB;EAEAC,MAAMA,CAAA,EAAG;IACP,OAAO,IAAI,CAACJ,GAAG,CAACI,MAAM,CAAC,CAAC;EAC1B;EAEAC,SAASA,CAAA,EAAa;IACpB,OAAO,IAAIC,wBAAW,CAAC,IAAI,CAACP,SAAS,EAAE,IAAI,CAACC,GAAG,CAACK,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAE,iBAAiBA,CAACC,MAAe,EAAEC,WAAwB,EAAW;IACpE,MAAMC,KAAK,GAAG,IAAI,CAACV,GAAG,CAACO,iBAAiB,CACtCC,MAAM,GACFG,KAAK,CAACC,IAAI,CAACC,oBAAS,CAACC,SAAS,CAAC,IAAI,CAACf,SAAS,EAAES,MAAM,CAAC,CAAC,GACvDO,SACN,CAAC;IACD,IAAIN,WAAW,EAAE;MACfA,WAAW,CAACT,GAAG,GAAGU,KAAK;IACzB;IACA,OAAO,IAAIM,sBAAU,CAAC,IAAI,CAACjB,SAAS,EAAEW,KAAK,CAAC;EAC9C;EAEAO,wBAAwBA,CAAA,EAAY;IAClCC,OAAO,CAACC,IAAI,CAAC,6CAA6C,CAAC;IAC3D,OAAO,IAAI;EACb;AACF;AAACC,OAAA,CAAAxB,YAAA,GAAAA,YAAA","ignoreList":[]}
|
@@ -100,7 +100,7 @@ const sksgHostConfig = exports.sksgHostConfig = {
|
|
100
100
|
preparePortalMount: () => {
|
101
101
|
debug("preparePortalMount");
|
102
102
|
},
|
103
|
-
cloneInstance(instance, _type, _oldProps, newProps,
|
103
|
+
cloneInstance(instance, _type, _oldProps, newProps, keepChildren, _newChildSet) {
|
104
104
|
debug("cloneInstance");
|
105
105
|
return {
|
106
106
|
type: instance.type,
|