-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move RuntimeScheduler initialisation to the start of the runtime
Summary: Changelog: [internal] RuntimeScheduler needs to be created and registered in the runtime before any JS is allowed to run. This diff moves the registration right after the runtime is initialised. This diff removes funnelling of Fabric events through RuntimeScheduler. This will be added in subsequent diff to keep the complexity low. Reviewed By: JoshuaGross Differential Revision: D29131766 fbshipit-source-id: cbc650f6fbce95e4b9c2c9695e8e0aba5beac635
- Loading branch information
1 parent
741b4d4
commit 1816536
Showing
7 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
ReactAndroid/src/main/java/com/facebook/react/fabric/RuntimeSchedulerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// (c) Facebook, Inc. and its affiliates. Confidential and proprietary. | ||
|
||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.fabric; | ||
|
||
import com.facebook.jni.HybridData; | ||
import com.facebook.proguard.annotations.DoNotStrip; | ||
import com.facebook.proguard.annotations.DoNotStripAny; | ||
import com.facebook.react.bridge.RuntimeExecutor; | ||
import com.facebook.soloader.SoLoader; | ||
|
||
@DoNotStripAny | ||
public class RuntimeSchedulerManager { | ||
|
||
static { | ||
staticInit(); | ||
} | ||
|
||
@DoNotStrip | ||
@SuppressWarnings("unused") | ||
private final HybridData mHybridData; | ||
|
||
public RuntimeSchedulerManager(RuntimeExecutor runtimeExecutor) { | ||
mHybridData = initHybrid(runtimeExecutor); | ||
installJSIBindings(); | ||
} | ||
|
||
private native HybridData initHybrid(RuntimeExecutor runtimeExecutor); | ||
|
||
private native void installJSIBindings(); | ||
|
||
private static void staticInit() { | ||
SoLoader.loadLibrary("fabricjni"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
ReactAndroid/src/main/java/com/facebook/react/fabric/jni/RuntimeSchedulerManager.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <jsi/jsi.h> | ||
#include <react/renderer/runtimescheduler/RuntimeScheduler.h> | ||
#include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h> | ||
|
||
#include "RuntimeSchedulerManager.h" | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
RuntimeSchedulerManager::RuntimeSchedulerManager( | ||
RuntimeExecutor runtimeExecutor) | ||
: runtimeExecutor_(runtimeExecutor) {} | ||
|
||
jni::local_ref<RuntimeSchedulerManager::jhybriddata> | ||
RuntimeSchedulerManager::initHybrid( | ||
jni::alias_ref<jclass>, | ||
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor) { | ||
return makeCxxInstance(runtimeExecutor->cthis()->get()); | ||
} | ||
|
||
void RuntimeSchedulerManager::registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod("initHybrid", RuntimeSchedulerManager::initHybrid), | ||
makeNativeMethod( | ||
"installJSIBindings", RuntimeSchedulerManager::installJSIBindings), | ||
}); | ||
} | ||
|
||
void RuntimeSchedulerManager::installJSIBindings() { | ||
runtimeExecutor_([runtimeExecutor = runtimeExecutor_](jsi::Runtime &runtime) { | ||
auto runtimeScheduler = std::make_shared<RuntimeScheduler>(runtimeExecutor); | ||
RuntimeSchedulerBinding::createAndInstallIfNeeded( | ||
runtime, runtimeScheduler); | ||
}); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
40 changes: 40 additions & 0 deletions
40
ReactAndroid/src/main/java/com/facebook/react/fabric/jni/RuntimeSchedulerManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ReactCommon/CallInvokerHolder.h> | ||
#include <ReactCommon/RuntimeExecutor.h> | ||
#include <fbjni/fbjni.h> | ||
#include <react/jni/JRuntimeExecutor.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
class RuntimeSchedulerManager | ||
: public facebook::jni::HybridClass<RuntimeSchedulerManager> { | ||
public: | ||
static auto constexpr kJavaDescriptor = | ||
"Lcom/facebook/react/fabric/RuntimeSchedulerManager;"; | ||
|
||
static facebook::jni::local_ref<jhybriddata> initHybrid( | ||
jni::alias_ref<jclass>, | ||
facebook::jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor); | ||
|
||
static void registerNatives(); | ||
|
||
private: | ||
friend HybridBase; | ||
RuntimeExecutor runtimeExecutor_; | ||
|
||
void installJSIBindings(); | ||
|
||
explicit RuntimeSchedulerManager(RuntimeExecutor runtimeExecutor); | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |