Skip to content

Commit cdfc240

Browse files
committed
chore: wip
1 parent 90dbc2b commit cdfc240

25 files changed

Lines changed: 328 additions & 490 deletions

packages/react-native-worklets/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ JSIWorkletsModuleProxy::JSIWorkletsModuleProxy(
158158
const std::shared_ptr<RuntimeManager> &runtimeManager,
159159
const std::weak_ptr<WorkletRuntime> &uiWorkletRuntime,
160160
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
161-
const BundleModeConfig &bundleModeConfig)
161+
const BundleModeConfig &bundleModeConfig,
162+
const std::shared_ptr<UnpackerLoader> &unpackerLoader)
162163
: jsi::HostObject(),
163164
isDevBundle_(isDevBundle),
164165
bundleModeConfig_(bundleModeConfig),
@@ -168,13 +169,16 @@ JSIWorkletsModuleProxy::JSIWorkletsModuleProxy(
168169
memoryManager_(memoryManager),
169170
runtimeManager_(runtimeManager),
170171
uiWorkletRuntime_(uiWorkletRuntime),
171-
runtimeBindings_(runtimeBindings) {}
172+
runtimeBindings_(runtimeBindings),
173+
unpackerLoader_(unpackerLoader) {}
172174

173175
JSIWorkletsModuleProxy::~JSIWorkletsModuleProxy() = default;
174176

175177
std::vector<jsi::PropNameID> JSIWorkletsModuleProxy::getPropertyNames(jsi::Runtime &rt) {
176178
std::vector<jsi::PropNameID> propertyNames;
177179

180+
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "loadUnpackers"));
181+
178182
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "createSerializable"));
179183
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "createSerializableBigInt"));
180184
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "createSerializableBoolean"));
@@ -221,12 +225,66 @@ std::vector<jsi::PropNameID> JSIWorkletsModuleProxy::getPropertyNames(jsi::Runti
221225
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "getUIRuntimeHolder"));
222226
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "getUISchedulerHolder"));
223227

228+
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "getUIRuntimeHolder"));
229+
propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "getUISchedulerHolder"));
230+
224231
return propertyNames;
225232
}
226233

227234
jsi::Value JSIWorkletsModuleProxy::get(jsi::Runtime &rt, const jsi::PropNameID &propName) {
228235
const auto name = propName.utf8(rt);
229236

237+
if (name == "loadUnpackers") {
238+
return jsi::Function::createFromHostFunction(
239+
rt,
240+
propName,
241+
9,
242+
[unpackerLoader = unpackerLoader_](
243+
jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
244+
const auto valueUnpackerCode = args[0].asString(rt).utf8(rt);
245+
const auto valueUnpackerLocation = args[1].asString(rt).utf8(rt);
246+
const auto valueUnpackerSourceMap = args[2].asString(rt).utf8(rt);
247+
248+
const auto synchronizableUnpackerCode = args[3].asString(rt).utf8(rt);
249+
const auto synchronizableUnpackerLocation = args[4].asString(rt).utf8(rt);
250+
const auto synchronizableUnpackerSourceMap = args[5].asString(rt).utf8(rt);
251+
252+
const auto customSerializableUnpackerCode = args[6].asString(rt).utf8(rt);
253+
const auto customSerializableUnpackerLocation = args[7].asString(rt).utf8(rt);
254+
const auto customSerializableUnpackerSourceMap = args[8].asString(rt).utf8(rt);
255+
256+
const auto shareableHostUnpackerCode = args[9].asString(rt).utf8(rt);
257+
const auto shareableHostUnpackerLocation = args[10].asString(rt).utf8(rt);
258+
const auto shareableHostUnpackerSourceMap = args[11].asString(rt).utf8(rt);
259+
260+
const auto shareableGuestUnpackerCode = args[12].asString(rt).utf8(rt);
261+
const auto shareableGuestUnpackerLocation = args[13].asString(rt).utf8(rt);
262+
const auto shareableGuestUnpackerSourceMap = args[14].asString(rt).utf8(rt);
263+
264+
unpackerLoader->loadUnpackers(ShareableUnpackers{
265+
.valueUnpacker =
266+
{.code = valueUnpackerCode, .location = valueUnpackerLocation, .sourceMap = valueUnpackerSourceMap},
267+
.synchronizableUnpacker =
268+
{.code = synchronizableUnpackerCode,
269+
.location = synchronizableUnpackerLocation,
270+
.sourceMap = synchronizableUnpackerSourceMap},
271+
.customSerializableUnpacker =
272+
{.code = customSerializableUnpackerCode,
273+
.location = customSerializableUnpackerLocation,
274+
.sourceMap = customSerializableUnpackerSourceMap},
275+
.shareableHostUnpacker =
276+
{.code = shareableHostUnpackerCode,
277+
.location = shareableHostUnpackerLocation,
278+
.sourceMap = shareableHostUnpackerSourceMap},
279+
.shareableGuestUnpacker =
280+
{.code = shareableGuestUnpackerCode,
281+
.location = shareableGuestUnpackerLocation,
282+
.sourceMap = shareableGuestUnpackerSourceMap},
283+
});
284+
return jsi::Value::undefined();
285+
});
286+
}
287+
230288
if (name == "createSerializable") {
231289
return jsi::Function::createFromHostFunction(
232290
rt, propName, 3, [](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {

packages/react-native-worklets/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <react/renderer/uimanager/primitives.h>
77
#include <worklets/SharedItems/MemoryManager.h>
88
#include <worklets/SharedItems/Serializable.h>
9+
#include <worklets/SharedItems/UnpackerLoader.h>
910
#include <worklets/Tools/Defs.h>
1011
#include <worklets/Tools/ScriptBuffer.h>
1112
#include <worklets/WorkletRuntime/BundleModeConfig.h>
@@ -34,7 +35,8 @@ class JSIWorkletsModuleProxy : public jsi::HostObject {
3435
const std::shared_ptr<RuntimeManager> &runtimeManager,
3536
const std::weak_ptr<WorkletRuntime> &uiWorkletRuntime,
3637
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
37-
const BundleModeConfig &bundleModeConfig);
38+
const BundleModeConfig &bundleModeConfig,
39+
const std::shared_ptr<UnpackerLoader> &unpackerLoader);
3840

3941
JSIWorkletsModuleProxy(const JSIWorkletsModuleProxy &other) = default;
4042

@@ -84,6 +86,10 @@ class JSIWorkletsModuleProxy : public jsi::HostObject {
8486
return runtimeBindings_;
8587
}
8688

89+
[[nodiscard]] std::shared_ptr<UnpackerLoader> getUnpackerLoader() const {
90+
return unpackerLoader_;
91+
}
92+
8793
private:
8894
const bool isDevBundle_;
8995
const BundleModeConfig bundleModeConfig_;
@@ -94,6 +100,7 @@ class JSIWorkletsModuleProxy : public jsi::HostObject {
94100
const std::shared_ptr<RuntimeManager> runtimeManager_;
95101
const std::weak_ptr<WorkletRuntime> uiWorkletRuntime_;
96102
const std::shared_ptr<RuntimeBindings> runtimeBindings_;
103+
const std::shared_ptr<UnpackerLoader> unpackerLoader_;
97104
};
98105

99106
} // namespace worklets

packages/react-native-worklets/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ bool isDevBundleFromRNRuntime(jsi::Runtime &rnRuntime) {
2222
return rtDev.isBool() && rtDev.asBool();
2323
}
2424

25+
/**
26+
* This method is required outside of Bundle Mode to make sure we start creating
27+
* Worklet Runtimes only after unpackers code was loaded from the RN Runtime.
28+
*
29+
* In Bundle Mode unpackers are installed during bundle evaluation instead.
30+
*/
2531
void WorkletsModuleProxy::start() {
2632
/**
2733
* We call additional `init` method here because
@@ -53,6 +59,7 @@ WorkletsModuleProxy::WorkletsModuleProxy(
5359
bundleModeConfig_(bundleModeConfig),
5460
memoryManager_(std::make_shared<MemoryManager>()),
5561
runtimeManager_(std::make_shared<RuntimeManager>()),
62+
unpackerLoader_(std::make_shared<UnpackerLoader>()),
5663
uiWorkletRuntime_(
5764
runtimeManager_->createUninitializedUIRuntime(jsQueue_, std::make_shared<AsyncQueueUI>(uiScheduler_))),
5865
rnRuntimeProxy_(std::make_shared<JSIWorkletsModuleProxy>(
@@ -64,7 +71,8 @@ WorkletsModuleProxy::WorkletsModuleProxy(
6471
runtimeManager_,
6572
uiWorkletRuntime_,
6673
runtimeBindings_,
67-
bundleModeConfig_)) {
74+
bundleModeConfig_,
75+
unpackerLoader_)) {
6876
auto optimizedJsiWorkletsModuleProxy =
6977
jsi_utils::optimizedFromHostObject(rnRuntime, std::static_pointer_cast<jsi::HostObject>(rnRuntimeProxy_));
7078
RNRuntimeWorkletDecorator::decorate(rnRuntime, std::move(optimizedJsiWorkletsModuleProxy), jsLogger_);

packages/react-native-worklets/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <worklets/AnimationFrameQueue/AnimationFrameBatchinator.h>
77
#include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
88
#include <worklets/SharedItems/MemoryManager.h>
9+
#include <worklets/SharedItems/UnpackerLoader.h>
910
#include <worklets/Tools/Defs.h>
1011
#include <worklets/Tools/JSLogger.h>
1112
#include <worklets/Tools/JSScheduler.h>
@@ -71,6 +72,7 @@ class WorkletsModuleProxy : public std::enable_shared_from_this<WorkletsModulePr
7172
const BundleModeConfig bundleModeConfig_;
7273
const std::shared_ptr<MemoryManager> memoryManager_;
7374
const std::shared_ptr<RuntimeManager> runtimeManager_;
75+
const std::shared_ptr<UnpackerLoader> unpackerLoader_;
7476
std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
7577
const std::shared_ptr<JSIWorkletsModuleProxy> rnRuntimeProxy_;
7678
std::shared_ptr<AnimationFrameBatchinator> animationFrameBatchinator_;

packages/react-native-worklets/Common/cpp/worklets/Resources/CustomSerializableUnpacker.cpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/react-native-worklets/Common/cpp/worklets/Resources/ShareableGuestUnpacker.cpp

Lines changed: 0 additions & 178 deletions
This file was deleted.

0 commit comments

Comments
 (0)