|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 |
| -#define FML_USED_ON_EMBEDDER |
6 |
| - |
7 | 5 | #include "engine.h"
|
8 | 6 |
|
9 | 7 | #include <lib/async/cpp/task.h>
|
|
21 | 19 | #include "fuchsia_intl.h"
|
22 | 20 | #include "platform_view.h"
|
23 | 21 | #include "runtime/dart/utils/files.h"
|
| 22 | +#include "task_runner_adapter.h" |
24 | 23 | #include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
|
| 24 | +#include "thread.h" |
25 | 25 |
|
26 | 26 | namespace flutter_runner {
|
27 | 27 |
|
@@ -60,17 +60,19 @@ Engine::Engine(Delegate& delegate,
|
60 | 60 | fidl::InterfaceRequest<fuchsia::io::Directory> directory_request)
|
61 | 61 | : delegate_(delegate),
|
62 | 62 | 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), |
67 | 63 | settings_(std::move(settings)),
|
68 | 64 | weak_factory_(this) {
|
69 | 65 | if (zx::event::create(0, &vsync_event_) != ZX_OK) {
|
70 | 66 | FML_DLOG(ERROR) << "Could not create the vsync event.";
|
71 | 67 | return;
|
72 | 68 | }
|
73 | 69 |
|
| 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 | + |
74 | 76 | // Set up the session connection.
|
75 | 77 | auto scenic = svc->Connect<fuchsia::ui::scenic::Scenic>();
|
76 | 78 | fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session;
|
@@ -170,14 +172,12 @@ Engine::Engine(Delegate& delegate,
|
170 | 172 |
|
171 | 173 | // Get the task runners from the managed threads. The current thread will be
|
172 | 174 | // used as the "platform" thread.
|
173 |
| - fml::MessageLoop::EnsureInitializedForCurrentThread(); |
174 |
| - |
175 | 175 | const flutter::TaskRunners task_runners(
|
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 |
| 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 |
181 | 181 | );
|
182 | 182 |
|
183 | 183 | // Setup the callback that will instantiate the rasterizer.
|
@@ -359,6 +359,12 @@ Engine::Engine(Delegate& delegate,
|
359 | 359 |
|
360 | 360 | Engine::~Engine() {
|
361 | 361 | shell_.reset();
|
| 362 | + for (const auto& thread : threads_) { |
| 363 | + thread->Quit(); |
| 364 | + } |
| 365 | + for (const auto& thread : threads_) { |
| 366 | + thread->Join(); |
| 367 | + } |
362 | 368 | }
|
363 | 369 |
|
364 | 370 | std::pair<bool, uint32_t> Engine::GetEngineReturnCode() const {
|
|
0 commit comments