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

Commit 739e190

Browse files
author
George Wright
committed
Migrate flutter_runner from flutter_runner::{Thread,Loop} to
fml::{Thread,MessageLoop}
1 parent eb13993 commit 739e190

21 files changed

+75
-288
lines changed

fml/message_loop.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,4 @@ TaskQueueId MessageLoop::GetCurrentTaskQueueId() {
8080
"this thread prior to message loop use.";
8181
return loop->GetLoopImpl()->GetTaskQueueId();
8282
}
83-
8483
} // namespace fml

fml/message_loop_impl.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,8 @@ TaskQueueId MessageLoopImpl::GetTaskQueueId() const {
145145
return queue_id_;
146146
}
147147

148+
fml::RefPtr<MessageLoopImpl> MessageLoopImpl::GetLoopImpl(MessageLoop& message_loop) {
149+
return message_loop.GetLoopImpl();
150+
}
151+
148152
} // namespace fml

fml/message_loop_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class MessageLoopImpl : public Wakeable,
5858
protected:
5959
MessageLoopImpl();
6060

61+
static fml::RefPtr<MessageLoopImpl> GetLoopImpl(MessageLoop& loop);
62+
6163
private:
6264
fml::RefPtr<MessageLoopTaskQueues> task_queue_;
6365
TaskQueueId queue_id_;

fml/platform/fuchsia/message_loop_fuchsia.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ void MessageLoopFuchsia::WakeUp(fml::TimePoint time_point) {
3535
FML_DCHECK(status == ZX_OK);
3636
}
3737

38+
// TODO(gw280): This is needed in order to get the underlying async::Loop object to pass to other Fuchsia components,
39+
// such as the Trace component.
40+
async::Loop* MessageLoopFuchsia::FuchsiaLoopForMessageLoop(MessageLoop& message_loop) {
41+
MessageLoopFuchsia* loop_impl = (MessageLoopFuchsia*)MessageLoopImpl::GetLoopImpl(message_loop).get();
42+
return loop_impl->GetAsyncLoop();
43+
}
44+
45+
async::Loop* MessageLoopFuchsia::GetAsyncLoop() {
46+
return &loop_;
47+
}
48+
3849
} // namespace fml

fml/platform/fuchsia/message_loop_fuchsia.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
namespace fml {
1414

1515
class MessageLoopFuchsia : public MessageLoopImpl {
16+
public:
17+
static async::Loop* FuchsiaLoopForMessageLoop(MessageLoop& message_loop);
18+
1619
private:
1720
MessageLoopFuchsia();
1821

@@ -24,6 +27,8 @@ class MessageLoopFuchsia : public MessageLoopImpl {
2427

2528
void WakeUp(fml::TimePoint time_point) override;
2629

30+
async::Loop* GetAsyncLoop();
31+
2732
async::Loop loop_;
2833

2934
FML_FRIEND_MAKE_REF_COUNTED(MessageLoopFuchsia);

fml/thread.cc

Lines changed: 5 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,9 @@ 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(),
92+
name.size());
8893
#else
8994
FML_DLOG(INFO) << "Could not set the thread name to '" << name
9095
<< "' on this platform.";

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 0 additions & 4 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",
@@ -317,8 +315,6 @@ executable("flutter_runner_unittests") {
317315
"task_observers.h",
318316
"task_runner_adapter.cc",
319317
"task_runner_adapter.h",
320-
"thread.cc",
321-
"thread.h",
322318
"vsync_recorder.cc",
323319
"vsync_recorder.h",
324320
"vsync_waiter.cc",

shell/platform/fuchsia/flutter/component.cc

Lines changed: 5 additions & 5 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>
@@ -37,7 +39,6 @@
3739

3840
#include "task_observers.h"
3941
#include "task_runner_adapter.h"
40-
#include "thread.h"
4142

4243
// TODO(kaushikiska): Use these constants from ::llcpp::fuchsia::io
4344
// Can read from target object.
@@ -58,11 +59,11 @@ ActiveApplication Application::Create(
5859
fuchsia::sys::StartupInfo startup_info,
5960
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
6061
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
61-
std::unique_ptr<Thread> thread = std::make_unique<Thread>();
62+
std::unique_ptr<fml::Thread> thread = std::make_unique<fml::Thread>();
6263
std::unique_ptr<Application> application;
6364

6465
fml::AutoResetWaitableEvent latch;
65-
async::PostTask(thread->dispatcher(), [&]() mutable {
66+
fml::TaskRunner::RunNowOrPostTask(thread->GetTaskRunner(), [&]() mutable {
6667
application.reset(
6768
new Application(std::move(termination_callback), std::move(package),
6869
std::move(startup_info), runner_incoming_services,
@@ -372,8 +373,7 @@ Application::Application(
372373
#endif // defined(__aarch64__)
373374

374375
auto weak_application = weak_factory_.GetWeakPtr();
375-
auto platform_task_runner =
376-
CreateFMLTaskRunner(async_get_default_dispatcher());
376+
auto platform_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
377377
const std::string component_url = package.resolved_url;
378378
settings_.unhandled_exception_callback = [weak_application,
379379
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: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "runtime/dart/utils/files.h"
2121
#include "task_runner_adapter.h"
2222
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
23-
#include "thread.h"
2423

2524
namespace flutter_runner {
2625

@@ -60,19 +59,16 @@ Engine::Engine(Delegate& delegate,
6059
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request)
6160
: delegate_(delegate),
6261
thread_label_(std::move(thread_label)),
62+
thread_host_(thread_label_ + ".",
63+
flutter::ThreadHost::Type::Platform | flutter::ThreadHost::Type::IO |
64+
flutter::ThreadHost::Type::UI | flutter::ThreadHost::Type::GPU),
6365
settings_(std::move(settings)),
6466
weak_factory_(this) {
6567
if (zx::event::create(0, &vsync_event_) != ZX_OK) {
6668
FML_DLOG(ERROR) << "Could not create the vsync event.";
6769
return;
6870
}
6971

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-
7672
// Set up the session connection.
7773
auto scenic = svc->Connect<fuchsia::ui::scenic::Scenic>();
7874
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session;
@@ -169,10 +165,10 @@ Engine::Engine(Delegate& delegate,
169165
// used as the "platform" thread.
170166
const flutter::TaskRunners task_runners(
171167
thread_label_, // Dart thread labels
172-
CreateFMLTaskRunner(async_get_default_dispatcher()), // platform
173-
CreateFMLTaskRunner(threads_[0]->dispatcher()), // gpu
174-
CreateFMLTaskRunner(threads_[1]->dispatcher()), // ui
175-
CreateFMLTaskRunner(threads_[2]->dispatcher()) // io
168+
thread_host_.platform_thread->GetTaskRunner(), // platform
169+
thread_host_.gpu_thread->GetTaskRunner(), // gpu
170+
thread_host_.ui_thread->GetTaskRunner(), // ui
171+
thread_host_.io_thread->GetTaskRunner() // io
176172
);
177173

178174
// Setup the callback that will instantiate the rasterizer.
@@ -352,12 +348,6 @@ Engine::Engine(Delegate& delegate,
352348

353349
Engine::~Engine() {
354350
shell_.reset();
355-
for (const auto& thread : threads_) {
356-
thread->Quit();
357-
}
358-
for (const auto& thread : threads_) {
359-
thread->Join();
360-
}
361351
}
362352

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

0 commit comments

Comments
 (0)