Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d0fd04a

Browse files
author
Jonah Williams
authored
[engine] add back opt out for merged threads. (#55952)
Add back opt out for merged threads for customer money.
1 parent 42c2a40 commit d0fd04a

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

common/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ struct Settings {
363363
///
364364
/// This is used by the runOnPlatformThread API.
365365
bool enable_platform_isolates = false;
366+
367+
// If true, the UI thread is the platform thread on supported
368+
// platforms.
369+
bool merged_platform_ui_thread = true;
366370
};
367371

368372
} // namespace flutter

shell/common/switches.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
529529
settings.disable_surface_control = command_line.HasOption(
530530
FlagForSwitch(Switch::DisableAndroidSurfaceControl));
531531

532+
settings.merged_platform_ui_thread = !command_line.HasOption(
533+
FlagForSwitch(Switch::DisableMergedPlatformUIThread));
534+
532535
return settings;
533536
}
534537

shell/common/switches.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ DEF_SWITCH(EnableEmbedderAPI,
294294
DEF_SWITCH(EnablePlatformIsolates,
295295
"enable-platform-isolates",
296296
"Enable support for isolates that run on the platform thread.")
297-
DEF_SWITCH(EnableMergedPlatformUIThread,
298-
"enable-merged-platform-ui-thread",
297+
DEF_SWITCH(DisableMergedPlatformUIThread,
298+
"no-enable-merged-platform-ui-thread",
299299
"Merge the ui thread and platform thread.")
300300
DEF_SWITCH(DisableAndroidSurfaceControl,
301301
"disable-surface-control",

shell/platform/android/android_shell_holder.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ AndroidShellHolder::AndroidShellHolder(
9090
auto thread_label = std::to_string(thread_host_count++);
9191

9292
auto mask = ThreadHost::Type::kRaster | ThreadHost::Type::kIo;
93+
if (!settings.merged_platform_ui_thread) {
94+
mask |= ThreadHost::Type::kUi;
95+
}
9396

9497
flutter::ThreadHost::ThreadHostConfig host_config(
9598
thread_label, mask, AndroidPlatformThreadConfigSetter);
@@ -136,7 +139,11 @@ AndroidShellHolder::AndroidShellHolder(
136139
fml::RefPtr<fml::TaskRunner> platform_runner =
137140
fml::MessageLoop::GetCurrent().GetTaskRunner();
138141
raster_runner = thread_host_->raster_thread->GetTaskRunner();
139-
ui_runner = platform_runner;
142+
if (settings.merged_platform_ui_thread) {
143+
ui_runner = platform_runner;
144+
} else {
145+
ui_runner = thread_host_->ui_thread->GetTaskRunner();
146+
}
140147
io_runner = thread_host_->io_thread->GetTaskRunner();
141148

142149
flutter::TaskRunners task_runners(thread_label, // label

shell/platform/android/android_shell_holder_unittests.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,19 @@ TEST(AndroidShellHolder, CreateWithMergedPlatformAndUIThread) {
174174
holder->GetShellForTesting()->GetTaskRunners().GetPlatformTaskRunner());
175175
}
176176

177+
TEST(AndroidShellHolder, CreateWithUnMergedPlatformAndUIThread) {
178+
Settings settings;
179+
settings.merged_platform_ui_thread = false;
180+
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
181+
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
182+
auto window = fml::MakeRefCounted<AndroidNativeWindow>(
183+
nullptr, /*is_fake_window=*/true);
184+
holder->GetPlatformView()->NotifyCreated(window);
185+
186+
EXPECT_NE(
187+
holder->GetShellForTesting()->GetTaskRunners().GetUITaskRunner(),
188+
holder->GetShellForTesting()->GetTaskRunners().GetPlatformTaskRunner());
189+
}
190+
177191
} // namespace testing
178192
} // namespace flutter

shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class FlutterLoader {
4747
"io.flutter.embedding.android.EnableOpenGLGPUTracing";
4848
private static final String IMPELLER_VULKAN_GPU_TRACING_DATA_KEY =
4949
"io.flutter.embedding.android.EnableVulkanGPUTracing";
50-
private static final String ENABLED_MERGED_PLATFORM_UI_THREAD_KEY =
51-
"io.flutter.embedding.android.EnableMergedPlatformUIThread";
50+
private static final String DISABLE_MERGED_PLATFORM_UI_THREAD_KEY =
51+
"io.flutter.embedding.android.DisableMergedPlatformUIThread";
5252
private static final String DISABLE_SURFACE_CONTROL =
5353
"io.flutter.embedding.android.DisableSurfaceControl";
5454

@@ -363,17 +363,16 @@ public void ensureInitializationComplete(
363363
if (metaData.getBoolean(IMPELLER_VULKAN_GPU_TRACING_DATA_KEY, false)) {
364364
shellArgs.add("--enable-vulkan-gpu-tracing");
365365
}
366-
if (metaData.getBoolean(DISABLE_SURFACE_CONTROL, false)) {
367-
shellArgs.add("--disable-surface-control");
368-
}
369-
if (metaData.containsKey(ENABLED_MERGED_PLATFORM_UI_THREAD_KEY)) {
370-
if (metaData.getBoolean(ENABLED_MERGED_PLATFORM_UI_THREAD_KEY)) {
371-
shellArgs.add("--enable-merged-platform-ui-thread");
372-
} else {
366+
if (metaData.containsKey(DISABLE_MERGED_PLATFORM_UI_THREAD_KEY)) {
367+
if (metaData.getBoolean(DISABLE_MERGED_PLATFORM_UI_THREAD_KEY)) {
373368
shellArgs.add("--no-enable-merged-platform-ui-thread");
374369
}
375370
}
376371

372+
if (metaData.getBoolean(DISABLE_SURFACE_CONTROL, false)) {
373+
shellArgs.add("--disable-surface-control");
374+
}
375+
377376
String backend = metaData.getString(IMPELLER_BACKEND_META_DATA_KEY);
378377
if (backend != null) {
379378
shellArgs.add("--impeller-backend=" + backend);

0 commit comments

Comments
 (0)