Skip to content

Commit 8fae291

Browse files
committed
Reland "[Windows] Enable merged platform and UI thread by default" (flutter#167420)"
This reverts commit 66ecc88.
1 parent f71b4fe commit 8fae291

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,12 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
299299
custom_task_runners.thread_priority_setter =
300300
&WindowsPlatformThreadPrioritySetter;
301301

302-
if (project_->ui_thread_policy() ==
303-
FlutterUIThreadPolicy::RunOnPlatformThread) {
304-
FML_LOG(WARNING)
305-
<< "Running with merged platform and UI thread. Experimental.";
302+
if (project_->ui_thread_policy() !=
303+
FlutterUIThreadPolicy::RunOnSeparateThread) {
306304
custom_task_runners.ui_task_runner = &platform_task_runner;
305+
} else {
306+
FML_LOG(WARNING) << "Running with unmerged platform and UI threads. This "
307+
"will be removed in future.";
307308
}
308309

309310
FlutterProjectArgs args = {};

engine/src/flutter/shell/platform/windows/flutter_windows_unittests.cc

+36-26
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,23 @@ TEST_F(WindowsTest, LaunchHeadlessEngine) {
131131
ASSERT_NE(engine, nullptr);
132132

133133
std::string view_ids;
134-
fml::AutoResetWaitableEvent latch;
134+
bool signaled = false;
135135
context.AddNativeFunction(
136136
"SignalStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
137137
auto handle = Dart_GetNativeArgument(args, 0);
138138
ASSERT_FALSE(Dart_IsError(handle));
139139
view_ids = tonic::DartConverter<std::string>::FromDart(handle);
140-
latch.Signal();
140+
signaled = true;
141141
}));
142142

143143
ViewControllerPtr controller{builder.Run()};
144144
ASSERT_NE(controller, nullptr);
145145

146+
while (!signaled) {
147+
PumpMessage();
148+
}
149+
146150
// Verify a headless app has the implicit view.
147-
latch.Wait();
148151
EXPECT_EQ(view_ids, "View IDs: [0]");
149152
}
150153

@@ -214,16 +217,18 @@ TEST_F(WindowsTest, VerifyNativeFunction) {
214217
WindowsConfigBuilder builder(context);
215218
builder.SetDartEntrypoint("verifyNativeFunction");
216219

217-
fml::AutoResetWaitableEvent latch;
220+
bool signaled = false;
218221
auto native_entry =
219-
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); });
222+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { signaled = true; });
220223
context.AddNativeFunction("Signal", native_entry);
221224

222225
ViewControllerPtr controller{builder.Run()};
223226
ASSERT_NE(controller, nullptr);
224227

225228
// Wait until signal has been called.
226-
latch.Wait();
229+
while (!signaled) {
230+
PumpMessage();
231+
}
227232
}
228233

229234
// Verify that native functions that pass parameters can be registered and
@@ -234,19 +239,21 @@ TEST_F(WindowsTest, VerifyNativeFunctionWithParameters) {
234239
builder.SetDartEntrypoint("verifyNativeFunctionWithParameters");
235240

236241
bool bool_value = false;
237-
fml::AutoResetWaitableEvent latch;
242+
bool signaled = false;
238243
auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
239244
auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value);
240245
ASSERT_FALSE(Dart_IsError(handle));
241-
latch.Signal();
246+
signaled = true;
242247
});
243248
context.AddNativeFunction("SignalBoolValue", native_entry);
244249

245250
ViewControllerPtr controller{builder.Run()};
246251
ASSERT_NE(controller, nullptr);
247252

248253
// Wait until signalBoolValue has been called.
249-
latch.Wait();
254+
while (!signaled) {
255+
PumpMessage();
256+
}
250257
EXPECT_TRUE(bool_value);
251258
}
252259

@@ -257,20 +264,22 @@ TEST_F(WindowsTest, PlatformExecutable) {
257264
builder.SetDartEntrypoint("readPlatformExecutable");
258265

259266
std::string executable_name;
260-
fml::AutoResetWaitableEvent latch;
267+
bool signaled = false;
261268
auto native_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
262269
auto handle = Dart_GetNativeArgument(args, 0);
263270
ASSERT_FALSE(Dart_IsError(handle));
264271
executable_name = tonic::DartConverter<std::string>::FromDart(handle);
265-
latch.Signal();
272+
signaled = true;
266273
});
267274
context.AddNativeFunction("SignalStringValue", native_entry);
268275

269276
ViewControllerPtr controller{builder.Run()};
270277
ASSERT_NE(controller, nullptr);
271278

272279
// Wait until signalStringValue has been called.
273-
latch.Wait();
280+
while (!signaled) {
281+
PumpMessage();
282+
}
274283
EXPECT_EQ(executable_name, "flutter_windows_unittests.exe");
275284
}
276285

@@ -282,26 +291,28 @@ TEST_F(WindowsTest, VerifyNativeFunctionWithReturn) {
282291
builder.SetDartEntrypoint("verifyNativeFunctionWithReturn");
283292

284293
bool bool_value_to_return = true;
285-
fml::CountDownLatch latch(2);
294+
int count = 2;
286295
auto bool_return_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
287296
Dart_SetBooleanReturnValue(args, bool_value_to_return);
288-
latch.CountDown();
297+
--count;
289298
});
290299
context.AddNativeFunction("SignalBoolReturn", bool_return_entry);
291300

292301
bool bool_value_passed = false;
293302
auto bool_pass_entry = CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
294303
auto handle = Dart_GetNativeBooleanArgument(args, 0, &bool_value_passed);
295304
ASSERT_FALSE(Dart_IsError(handle));
296-
latch.CountDown();
305+
--count;
297306
});
298307
context.AddNativeFunction("SignalBoolValue", bool_pass_entry);
299308

300309
ViewControllerPtr controller{builder.Run()};
301310
ASSERT_NE(controller, nullptr);
302311

303312
// Wait until signalBoolReturn and signalBoolValue have been called.
304-
latch.Wait();
313+
while (count > 0) {
314+
PumpMessage();
315+
}
305316
EXPECT_TRUE(bool_value_passed);
306317
}
307318

@@ -614,10 +625,10 @@ TEST_F(WindowsTest, AddRemoveView) {
614625
WindowsConfigBuilder builder(context);
615626
builder.SetDartEntrypoint("onMetricsChangedSignalViewIds");
616627

617-
fml::AutoResetWaitableEvent ready_latch;
628+
bool ready = false;
618629
context.AddNativeFunction(
619-
"Signal", CREATE_NATIVE_ENTRY(
620-
[&](Dart_NativeArguments args) { ready_latch.Signal(); }));
630+
"Signal",
631+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { ready = true; }));
621632

622633
context.AddNativeFunction(
623634
"SignalStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
@@ -632,7 +643,9 @@ TEST_F(WindowsTest, AddRemoveView) {
632643
ViewControllerPtr first_controller{builder.Run()};
633644
ASSERT_NE(first_controller, nullptr);
634645

635-
ready_latch.Wait();
646+
while (!ready) {
647+
PumpMessage();
648+
}
636649

637650
// Create a second view.
638651
FlutterDesktopEngineRef engine =
@@ -670,7 +683,6 @@ TEST_F(WindowsTest, EngineId) {
670683
WindowsConfigBuilder builder(context);
671684
builder.SetDartEntrypoint("testEngineId");
672685

673-
fml::AutoResetWaitableEvent latch;
674686
std::optional<int64_t> engineId;
675687
context.AddNativeFunction(
676688
"NotifyEngineId", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
@@ -679,17 +691,15 @@ TEST_F(WindowsTest, EngineId) {
679691
const auto handle = tonic::DartConverter<int64_t>::FromDart(argument);
680692
engineId = handle;
681693
}
682-
latch.Signal();
683694
}));
684695
// Create the implicit view.
685696
ViewControllerPtr first_controller{builder.Run()};
686697
ASSERT_NE(first_controller, nullptr);
687698

688-
latch.Wait();
689-
EXPECT_TRUE(engineId.has_value());
690-
if (!engineId.has_value()) {
691-
return;
699+
while (!engineId.has_value()) {
700+
PumpMessage();
692701
}
702+
693703
auto engine = FlutterDesktopViewControllerGetEngine(first_controller.get());
694704
EXPECT_EQ(engine, FlutterDesktopEngineForId(*engineId));
695705
}

0 commit comments

Comments
 (0)