From 831e2d41ab347f9bbcf2a90ad1ed13765952b3f3 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Thu, 13 May 2021 08:01:51 -0700 Subject: [PATCH] Funnel All Fabric calls to RuntimeExecutor to RuntimeScheduler Summary: Changelog: [internal] This diff moves all calls to RuntimeExecutor to RuntimeScheduler. The calls are still immediately dispatched. Timing of events will not change. The goal of this diff is to prepare infrastructure for Concurrent Mode. Reviewed By: JoshuaGross Differential Revision: D27938536 fbshipit-source-id: 750b0e21e0ecbd7aa5a14885ebc70aae82203bd4 --- .../java/com/facebook/react/fabric/jni/Android.mk | 3 ++- .../main/java/com/facebook/react/fabric/jni/BUCK | 1 + .../java/com/facebook/react/fabric/jni/Binding.cpp | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk index 528235e8f3e..64c8f3c532f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk @@ -11,7 +11,7 @@ LOCAL_MODULE := fabricjni LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) -LOCAL_SHARED_LIBRARIES := libreactconfig librrc_slider librrc_progressbar librrc_switch librrc_modal libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures libreact_render_mounting libreactnativeutilsjni libreact_utils libreact_render_debug libreact_render_graphics libreact_render_core react_render_componentregistry librrc_view librrc_unimplementedview librrc_root librrc_scrollview libbetter libreact_render_attributedstring libreact_render_uimanager libreact_render_templateprocessor libreact_render_scheduler libreact_render_animations libreact_render_imagemanager libreact_render_textlayoutmanager libreact_codegen_rncore rrc_text librrc_image librrc_textinput librrc_picker libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry +LOCAL_SHARED_LIBRARIES := libreactconfig librrc_slider librrc_progressbar librrc_switch librrc_modal libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures libreact_render_mounting libreactnativeutilsjni libreact_utils libreact_render_debug libreact_render_graphics libreact_render_core react_render_componentregistry librrc_view librrc_unimplementedview librrc_root librrc_scrollview libbetter libreact_render_attributedstring libreact_render_uimanager libreact_render_templateprocessor libreact_render_scheduler libreact_render_animations libreact_render_imagemanager libreact_render_textlayoutmanager libreact_codegen_rncore rrc_text librrc_image librrc_textinput librrc_picker libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry libreact_render_runtimescheduler LOCAL_STATIC_LIBRARIES := @@ -57,6 +57,7 @@ $(call import-module,react/renderer/graphics) $(call import-module,react/renderer/imagemanager) $(call import-module,react/renderer/mapbuffer) $(call import-module,react/renderer/mounting) +$(call import-module,react/renderer/runtimescheduler) $(call import-module,react/renderer/scheduler) $(call import-module,react/renderer/templateprocessor) $(call import-module,react/renderer/textlayoutmanager) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/BUCK b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/BUCK index 26a8474dd0c..16da889ff11 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/BUCK @@ -34,6 +34,7 @@ rn_xplat_cxx_library( react_native_xplat_target("react/renderer/scheduler:scheduler"), react_native_xplat_target("react/renderer/componentregistry:componentregistry"), react_native_xplat_target("react/renderer/components/scrollview:scrollview"), + react_native_xplat_target("react/renderer/runtimescheduler:runtimescheduler"), react_native_xplat_target("runtimeexecutor:runtimeexecutor"), react_native_target("jni/react/jni:jni"), "//xplat/fbsystrace:fbsystrace", diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp index 078ab334ff0..a141f5343e9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -499,6 +500,18 @@ void Binding::installFabricUIManager( auto sharedJSMessageQueueThread = std::make_shared(jsMessageQueueThread); auto runtimeExecutor = runtimeExecutorHolder->cthis()->get(); + std::shared_ptr runtimeScheduler; + + if (config->getBool("react_fabric:enable_runtimescheduler_android")) { + runtimeScheduler = std::make_shared(runtimeExecutor); + + auto originalRuntimeExecutor = runtimeExecutorHolder->cthis()->get(); + runtimeExecutor = + [originalRuntimeExecutor, runtimeScheduler]( + std::function &&callback) { + runtimeScheduler->scheduleWork(std::move(callback)); + }; + } auto enableV2AsynchronousEventBeat = config->getBool("react_fabric:enable_asynchronous_event_beat_v2_android"); @@ -551,6 +564,7 @@ void Binding::installFabricUIManager( toolbox.contextContainer = contextContainer; toolbox.componentRegistryFactory = componentsRegistry->buildRegistryFunction; toolbox.runtimeExecutor = runtimeExecutor; + toolbox.runtimeScheduler = runtimeScheduler; toolbox.synchronousEventBeatFactory = synchronousBeatFactory; toolbox.asynchronousEventBeatFactory = asynchronousBeatFactory;