[engine] add back opt out for merged threads. (flutter/engine#55952)

Add back opt out for merged threads for customer money.
This commit is contained in:
Jonah Williams
2024-10-18 10:51:49 -07:00
committed by GitHub
parent e203f1d40b
commit e7f4870f84
6 changed files with 39 additions and 12 deletions

View File

@@ -363,6 +363,10 @@ struct Settings {
///
/// 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

View File

@@ -529,6 +529,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.disable_surface_control = command_line.HasOption(
FlagForSwitch(Switch::DisableAndroidSurfaceControl));
settings.merged_platform_ui_thread = !command_line.HasOption(
FlagForSwitch(Switch::DisableMergedPlatformUIThread));
return settings;
}

View File

@@ -294,8 +294,8 @@ DEF_SWITCH(EnableEmbedderAPI,
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",

View File

@@ -90,6 +90,9 @@ AndroidShellHolder::AndroidShellHolder(
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 @@ AndroidShellHolder::AndroidShellHolder(
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

View File

@@ -174,5 +174,19 @@ TEST(AndroidShellHolder, CreateWithMergedPlatformAndUIThread) {
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

View File

@@ -47,8 +47,8 @@ public class FlutterLoader {
"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 @@ public class FlutterLoader {
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);