Skip to content

Commit 497fe1d

Browse files
authored
Revert "Revert "Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (flutter#15118)" (flutter#16277)"
This reverts commit 4b76686.
1 parent 7df7401 commit 497fe1d

21 files changed

+75
-448
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,8 +1025,6 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/extract_far.dart
10251025
FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/framework_shim.dart
10261026
FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/libraries.json
10271027
FILE: ../../../flutter/shell/platform/fuchsia/flutter/logging.h
1028-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/loop.cc
1029-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/loop.h
10301028
FILE: ../../../flutter/shell/platform/fuchsia/flutter/main.cc
10311029
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/aot_product_runtime
10321030
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/aot_runtime
@@ -1049,12 +1047,6 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.cc
10491047
FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.h
10501048
FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.cc
10511049
FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.h
1052-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_observers.cc
1053-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_observers.h
1054-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_runner_adapter.cc
1055-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_runner_adapter.h
1056-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/thread.cc
1057-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/thread.h
10581050
FILE: ../../../flutter/shell/platform/fuchsia/flutter/unique_fdio_ns.h
10591051
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_recorder.cc
10601052
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_recorder.h

fml/thread.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#if defined(OS_WIN)
1212
#include <windows.h>
13+
#elif defined(OS_FUCHSIA)
14+
#include <lib/zx/thread.h>
1315
#else
1416
#include <pthread.h>
1517
#endif
@@ -85,6 +87,8 @@ void Thread::SetCurrentThreadName(const std::string& name) {
8587
reinterpret_cast<DWORD_PTR*>(&info));
8688
} __except (EXCEPTION_CONTINUE_EXECUTION) {
8789
}
90+
#elif OS_FUCHSIA
91+
zx::thread::self()->set_property(ZX_PROP_NAME, name.c_str(), name.size());
8892
#else
8993
FML_DLOG(INFO) << "Could not set the thread name to '" << name
9094
<< "' on this platform.";

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ executable("flutter_runner_unittests") {
303303
"fuchsia_intl.h",
304304
"fuchsia_intl_unittest.cc",
305305
"logging.h",
306-
"loop.cc",
307-
"loop.h",
308306
"platform_view.cc",
309307
"platform_view.h",
310308
"platform_view_unittest.cc",
@@ -313,12 +311,6 @@ executable("flutter_runner_unittests") {
313311
"runner_unittest.cc",
314312
"surface.cc",
315313
"surface.h",
316-
"task_observers.cc",
317-
"task_observers.h",
318-
"task_runner_adapter.cc",
319-
"task_runner_adapter.h",
320-
"thread.cc",
321-
"thread.h",
322314
"vsync_recorder.cc",
323315
"vsync_recorder.h",
324316
"vsync_waiter.cc",

shell/platform/fuchsia/flutter/component.cc

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#define FML_USED_ON_EMBEDDER
6+
57
#include "component.h"
68

79
#include <dlfcn.h>
@@ -35,10 +37,6 @@
3537
#include "runtime/dart/utils/tempfs.h"
3638
#include "runtime/dart/utils/vmo.h"
3739

38-
#include "task_observers.h"
39-
#include "task_runner_adapter.h"
40-
#include "thread.h"
41-
4240
// TODO(kaushikiska): Use these constants from ::llcpp::fuchsia::io
4341
// Can read from target object.
4442
constexpr uint32_t OPEN_RIGHT_READABLE = 1u;
@@ -58,11 +56,11 @@ ActiveApplication Application::Create(
5856
fuchsia::sys::StartupInfo startup_info,
5957
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
6058
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
61-
std::unique_ptr<Thread> thread = std::make_unique<Thread>();
59+
std::unique_ptr<fml::Thread> thread = std::make_unique<fml::Thread>();
6260
std::unique_ptr<Application> application;
6361

6462
fml::AutoResetWaitableEvent latch;
65-
async::PostTask(thread->dispatcher(), [&]() mutable {
63+
fml::TaskRunner::RunNowOrPostTask(thread->GetTaskRunner(), [&]() mutable {
6664
application.reset(
6765
new Application(std::move(termination_callback), std::move(package),
6866
std::move(startup_info), runner_incoming_services,
@@ -346,12 +344,12 @@ Application::Application(
346344
settings_.disable_dart_asserts = true;
347345
#endif
348346

349-
settings_.task_observer_add =
350-
std::bind(&CurrentMessageLoopAddAfterTaskObserver, std::placeholders::_1,
351-
std::placeholders::_2);
352-
353-
settings_.task_observer_remove = std::bind(
354-
&CurrentMessageLoopRemoveAfterTaskObserver, std::placeholders::_1);
347+
settings_.task_observer_add = [](intptr_t key, fml::closure callback) {
348+
fml::MessageLoop::GetCurrent().AddTaskObserver(key, std::move(callback));
349+
};
350+
settings_.task_observer_remove = [](intptr_t key) {
351+
fml::MessageLoop::GetCurrent().RemoveTaskObserver(key);
352+
};
355353

356354
// TODO(FL-117): Re-enable causal async stack traces when this issue is
357355
// addressed.
@@ -378,8 +376,7 @@ Application::Application(
378376
#endif // defined(__aarch64__)
379377

380378
auto weak_application = weak_factory_.GetWeakPtr();
381-
auto platform_task_runner =
382-
CreateFMLTaskRunner(async_get_default_dispatcher());
379+
auto platform_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
383380
const std::string component_url = package.resolved_url;
384381
settings_.unhandled_exception_callback = [weak_application,
385382
platform_task_runner,

shell/platform/fuchsia/flutter/component.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
#include "engine.h"
2525
#include "flutter/common/settings.h"
2626
#include "flutter/fml/macros.h"
27+
#include "flutter/fml/thread.h"
2728

28-
#include "thread.h"
2929
#include "unique_fdio_ns.h"
3030

3131
namespace flutter_runner {
3232

3333
class Application;
3434

3535
struct ActiveApplication {
36-
std::unique_ptr<Thread> thread;
36+
std::unique_ptr<fml::Thread> thread;
3737
std::unique_ptr<Application> application;
3838

3939
ActiveApplication& operator=(ActiveApplication&& other) noexcept {

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#define FML_USED_ON_EMBEDDER
6+
57
#include "engine.h"
68

79
#include <lib/async/cpp/task.h>
@@ -19,9 +21,7 @@
1921
#include "fuchsia_intl.h"
2022
#include "platform_view.h"
2123
#include "runtime/dart/utils/files.h"
22-
#include "task_runner_adapter.h"
2324
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
24-
#include "thread.h"
2525

2626
namespace flutter_runner {
2727

@@ -60,19 +60,17 @@ Engine::Engine(Delegate& delegate,
6060
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request)
6161
: delegate_(delegate),
6262
thread_label_(std::move(thread_label)),
63+
thread_host_(thread_label_ + ".",
64+
flutter::ThreadHost::Type::IO |
65+
flutter::ThreadHost::Type::UI |
66+
flutter::ThreadHost::Type::GPU),
6367
settings_(std::move(settings)),
6468
weak_factory_(this) {
6569
if (zx::event::create(0, &vsync_event_) != ZX_OK) {
6670
FML_DLOG(ERROR) << "Could not create the vsync event.";
6771
return;
6872
}
6973

70-
// Launch the threads that will be used to run the shell. These threads will
71-
// be joined in the destructor.
72-
for (auto& thread : threads_) {
73-
thread.reset(new Thread());
74-
}
75-
7674
// Set up the session connection.
7775
auto scenic = svc->Connect<fuchsia::ui::scenic::Scenic>();
7876
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session;
@@ -172,12 +170,14 @@ Engine::Engine(Delegate& delegate,
172170

173171
// Get the task runners from the managed threads. The current thread will be
174172
// used as the "platform" thread.
173+
fml::MessageLoop::EnsureInitializedForCurrentThread();
174+
175175
const flutter::TaskRunners task_runners(
176-
thread_label_, // Dart thread labels
177-
CreateFMLTaskRunner(async_get_default_dispatcher()), // platform
178-
CreateFMLTaskRunner(threads_[0]->dispatcher()), // gpu
179-
CreateFMLTaskRunner(threads_[1]->dispatcher()), // ui
180-
CreateFMLTaskRunner(threads_[2]->dispatcher()) // io
176+
thread_label_, // Dart thread labels
177+
fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform
178+
thread_host_.gpu_thread->GetTaskRunner(), // gpu
179+
thread_host_.ui_thread->GetTaskRunner(), // ui
180+
thread_host_.io_thread->GetTaskRunner() // io
181181
);
182182

183183
// Setup the callback that will instantiate the rasterizer.
@@ -359,12 +359,6 @@ Engine::Engine(Delegate& delegate,
359359

360360
Engine::~Engine() {
361361
shell_.reset();
362-
for (const auto& thread : threads_) {
363-
thread->Quit();
364-
}
365-
for (const auto& thread : threads_) {
366-
thread->Join();
367-
}
368362
}
369363

370364
std::pair<bool, uint32_t> Engine::GetEngineReturnCode() const {

shell/platform/fuchsia/flutter/engine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "flutter/fml/macros.h"
1717
#include "flutter/shell/common/shell.h"
18+
#include "flutter/shell/common/thread_host.h"
1819
#include "isolate_configurator.h"
19-
#include "thread.h"
2020

2121
namespace flutter_runner {
2222

@@ -51,8 +51,8 @@ class Engine final {
5151
private:
5252
Delegate& delegate_;
5353
const std::string thread_label_;
54+
flutter::ThreadHost thread_host_;
5455
flutter::Settings settings_;
55-
std::array<std::unique_ptr<Thread>, 3> threads_;
5656
std::unique_ptr<IsolateConfigurator> isolate_configurator_;
5757
std::unique_ptr<flutter::Shell> shell_;
5858
zx::event vsync_event_;

shell/platform/fuchsia/flutter/engine_flutter_runner.gni

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ template("flutter_runner") {
5555
"isolate_configurator.cc",
5656
"isolate_configurator.h",
5757
"logging.h",
58-
"loop.cc",
59-
"loop.h",
6058
"main.cc",
6159
"platform_view.cc",
6260
"platform_view.h",
@@ -66,12 +64,6 @@ template("flutter_runner") {
6664
"session_connection.h",
6765
"surface.cc",
6866
"surface.h",
69-
"task_observers.cc",
70-
"task_observers.h",
71-
"task_runner_adapter.cc",
72-
"task_runner_adapter.h",
73-
"thread.cc",
74-
"thread.h",
7567
"unique_fdio_ns.h",
7668
"vsync_recorder.cc",
7769
"vsync_recorder.h",

shell/platform/fuchsia/flutter/fuchsia_intl.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <string>
99
#include <vector>
1010

11-
#include "loop.h"
1211
#include "rapidjson/document.h"
1312
#include "rapidjson/stringbuffer.h"
1413
#include "rapidjson/writer.h"

shell/platform/fuchsia/flutter/loop.cc

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)