diff --git a/common/settings.h b/common/settings.h index e17d8248f17df..689a0781d5e44 100644 --- a/common/settings.h +++ b/common/settings.h @@ -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 diff --git a/shell/common/switches.cc b/shell/common/switches.cc index e5c2fa01f75cb..b3bac173623e2 100644 --- a/shell/common/switches.cc +++ b/shell/common/switches.cc @@ -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; } diff --git a/shell/common/switches.h b/shell/common/switches.h index 25ecd83ae7cbc..1c1fb595b35d8 100644 --- a/shell/common/switches.h +++ b/shell/common/switches.h @@ -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", diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index 6ff32d8c83298..e86effe09bd92 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -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 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 d65bfae3c392a..88fb462305c10 100644 --- a/shell/platform/android/android_shell_holder_unittests.cc +++ b/shell/platform/android/android_shell_holder_unittests.cc @@ -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(); + auto holder = std::make_unique(settings, jni); + auto window = fml::MakeRefCounted( + 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 c9c55656e7449..8af3d1f7c0b63 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 @@ 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 void ensureInitializationComplete( 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);