Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion shell/platform/android/android_shell_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions shell/platform/android/android_shell_holder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
Expand Down