[engine] add back opt out for merged threads. (#55952)
Add back opt out for merged threads for customer money.
diff --git a/common/settings.h b/common/settings.h
index e17d824..689a078 100644
--- a/common/settings.h
+++ b/common/settings.h
@@ -363,6 +363,10 @@
///
/// This is used by the runOnPlatformThread API.
bool enable_platform_isolates = false;
+
+ // If true, the UI thread is the platform thread on supported
+ // platforms.
+ bool merged_platform_ui_thread = true;
};
} // namespace flutter
diff --git a/shell/common/switches.cc b/shell/common/switches.cc
index e5c2fa0..b3bac17 100644
--- a/shell/common/switches.cc
+++ b/shell/common/switches.cc
@@ -529,6 +529,9 @@
settings.disable_surface_control = command_line.HasOption(
FlagForSwitch(Switch::DisableAndroidSurfaceControl));
+ settings.merged_platform_ui_thread = !command_line.HasOption(
+ FlagForSwitch(Switch::DisableMergedPlatformUIThread));
+
return settings;
}
diff --git a/shell/common/switches.h b/shell/common/switches.h
index 25ecd83..1c1fb59 100644
--- a/shell/common/switches.h
+++ b/shell/common/switches.h
@@ -294,8 +294,8 @@
DEF_SWITCH(EnablePlatformIsolates,
"enable-platform-isolates",
"Enable support for isolates that run on the platform thread.")
-DEF_SWITCH(EnableMergedPlatformUIThread,
- "enable-merged-platform-ui-thread",
+DEF_SWITCH(DisableMergedPlatformUIThread,
+ "no-enable-merged-platform-ui-thread",
"Merge the ui thread and platform thread.")
DEF_SWITCH(DisableAndroidSurfaceControl,
"disable-surface-control",
diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc
index 6ff32d8..e86effe 100644
--- a/shell/platform/android/android_shell_holder.cc
+++ b/shell/platform/android/android_shell_holder.cc
@@ -90,6 +90,9 @@
auto thread_label = std::to_string(thread_host_count++);
auto mask = ThreadHost::Type::kRaster | ThreadHost::Type::kIo;
+ if (!settings.merged_platform_ui_thread) {
+ mask |= ThreadHost::Type::kUi;
+ }
flutter::ThreadHost::ThreadHostConfig host_config(
thread_label, mask, AndroidPlatformThreadConfigSetter);
@@ -136,7 +139,11 @@
fml::RefPtr<fml::TaskRunner> platform_runner =
fml::MessageLoop::GetCurrent().GetTaskRunner();
raster_runner = thread_host_->raster_thread->GetTaskRunner();
- ui_runner = platform_runner;
+ if (settings.merged_platform_ui_thread) {
+ ui_runner = platform_runner;
+ } else {
+ ui_runner = thread_host_->ui_thread->GetTaskRunner();
+ }
io_runner = thread_host_->io_thread->GetTaskRunner();
flutter::TaskRunners task_runners(thread_label, // label
diff --git a/shell/platform/android/android_shell_holder_unittests.cc b/shell/platform/android/android_shell_holder_unittests.cc
index d65bfae..88fb462 100644
--- a/shell/platform/android/android_shell_holder_unittests.cc
+++ b/shell/platform/android/android_shell_holder_unittests.cc
@@ -174,5 +174,19 @@
holder->GetShellForTesting()->GetTaskRunners().GetPlatformTaskRunner());
}
+TEST(AndroidShellHolder, CreateWithUnMergedPlatformAndUIThread) {
+ Settings settings;
+ settings.merged_platform_ui_thread = false;
+ auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
+ auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
+ auto window = fml::MakeRefCounted<AndroidNativeWindow>(
+ nullptr, /*is_fake_window=*/true);
+ holder->GetPlatformView()->NotifyCreated(window);
+
+ EXPECT_NE(
+ holder->GetShellForTesting()->GetTaskRunners().GetUITaskRunner(),
+ holder->GetShellForTesting()->GetTaskRunners().GetPlatformTaskRunner());
+}
+
} // namespace testing
} // namespace flutter
diff --git a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java
index c9c5565..8af3d1f 100644
--- a/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java
+++ b/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java
@@ -47,8 +47,8 @@
"io.flutter.embedding.android.EnableOpenGLGPUTracing";
private static final String IMPELLER_VULKAN_GPU_TRACING_DATA_KEY =
"io.flutter.embedding.android.EnableVulkanGPUTracing";
- private static final String ENABLED_MERGED_PLATFORM_UI_THREAD_KEY =
- "io.flutter.embedding.android.EnableMergedPlatformUIThread";
+ private static final String DISABLE_MERGED_PLATFORM_UI_THREAD_KEY =
+ "io.flutter.embedding.android.DisableMergedPlatformUIThread";
private static final String DISABLE_SURFACE_CONTROL =
"io.flutter.embedding.android.DisableSurfaceControl";
@@ -363,17 +363,16 @@
if (metaData.getBoolean(IMPELLER_VULKAN_GPU_TRACING_DATA_KEY, false)) {
shellArgs.add("--enable-vulkan-gpu-tracing");
}
- if (metaData.getBoolean(DISABLE_SURFACE_CONTROL, false)) {
- shellArgs.add("--disable-surface-control");
- }
- if (metaData.containsKey(ENABLED_MERGED_PLATFORM_UI_THREAD_KEY)) {
- if (metaData.getBoolean(ENABLED_MERGED_PLATFORM_UI_THREAD_KEY)) {
- shellArgs.add("--enable-merged-platform-ui-thread");
- } else {
+ if (metaData.containsKey(DISABLE_MERGED_PLATFORM_UI_THREAD_KEY)) {
+ if (metaData.getBoolean(DISABLE_MERGED_PLATFORM_UI_THREAD_KEY)) {
shellArgs.add("--no-enable-merged-platform-ui-thread");
}
}
+ if (metaData.getBoolean(DISABLE_SURFACE_CONTROL, false)) {
+ shellArgs.add("--disable-surface-control");
+ }
+
String backend = metaData.getString(IMPELLER_BACKEND_META_DATA_KEY);
if (backend != null) {
shellArgs.add("--impeller-backend=" + backend);