|
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 | + |
5 | 7 | #include "engine.h" |
6 | 8 |
|
7 | 9 | #include <lib/async/cpp/task.h> |
|
24 | 26 | #include "fuchsia_intl.h" |
25 | 27 | #include "platform_view.h" |
26 | 28 | #include "surface.h" |
27 | | -#include "task_runner_adapter.h" |
28 | 29 |
|
29 | 30 | #if defined(LEGACY_FUCHSIA_EMBEDDER) |
30 | 31 | #include "compositor_context.h" // nogncheck |
@@ -71,28 +72,17 @@ Engine::Engine(Delegate& delegate, |
71 | 72 | FlutterRunnerProductConfiguration product_config) |
72 | 73 | : delegate_(delegate), |
73 | 74 | thread_label_(std::move(thread_label)), |
74 | | -#if defined(LEGACY_FUCHSIA_EMBEDDER) |
75 | | - use_legacy_renderer_(product_config.use_legacy_renderer()), |
76 | | -#endif |
77 | | - intercept_all_input_(product_config.get_intercept_all_input()), |
| 75 | + thread_host_(thread_label_ + ".", |
| 76 | + flutter::ThreadHost::Type::IO | |
| 77 | + flutter::ThreadHost::Type::UI | |
| 78 | + flutter::ThreadHost::Type::GPU), |
78 | 79 | weak_factory_(this) { |
79 | 80 | if (zx::event::create(0, &vsync_event_) != ZX_OK) { |
80 | 81 | FML_DLOG(ERROR) << "Could not create the vsync event."; |
81 | 82 | return; |
82 | 83 | } |
83 | 84 |
|
84 | | - // Get the task runners from the managed threads. The current thread will be |
85 | | - // used as the "platform" thread. |
86 | | - const flutter::TaskRunners task_runners( |
87 | | - thread_label_, // Dart thread labels |
88 | | - CreateFMLTaskRunner(async_get_default_dispatcher()), // platform |
89 | | - CreateFMLTaskRunner(threads_[0].dispatcher()), // raster |
90 | | - CreateFMLTaskRunner(threads_[1].dispatcher()), // ui |
91 | | - CreateFMLTaskRunner(threads_[2].dispatcher()) // io |
92 | | - ); |
93 | | - UpdateNativeThreadLabelNames(thread_label_, task_runners); |
94 | | - |
95 | | - // Connect to Scenic. |
| 85 | + // Set up the session connection. |
96 | 86 | auto scenic = svc->Connect<fuchsia::ui::scenic::Scenic>(); |
97 | 87 | fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session; |
98 | 88 | fidl::InterfaceHandle<fuchsia::ui::scenic::SessionListener> session_listener; |
@@ -274,6 +264,34 @@ Engine::Engine(Delegate& delegate, |
274 | 264 | vsync_handle); |
275 | 265 | }); |
276 | 266 |
|
| 267 | + // Session can be terminated on the GPU thread, but we must terminate |
| 268 | + // ourselves on the platform thread. |
| 269 | + // |
| 270 | + // This handles the fidl error callback when the Session connection is |
| 271 | + // broken. The SessionListener interface also has an OnError method, which is |
| 272 | + // invoked on the platform thread (in PlatformView). |
| 273 | + fml::closure on_session_error_callback = |
| 274 | + [dispatcher = async_get_default_dispatcher(), |
| 275 | + weak = weak_factory_.GetWeakPtr()]() { |
| 276 | + async::PostTask(dispatcher, [weak]() { |
| 277 | + if (weak) { |
| 278 | + weak->Terminate(); |
| 279 | + } |
| 280 | + }); |
| 281 | + }; |
| 282 | + |
| 283 | + // Get the task runners from the managed threads. The current thread will be |
| 284 | + // used as the "platform" thread. |
| 285 | + fml::MessageLoop::EnsureInitializedForCurrentThread(); |
| 286 | + |
| 287 | + const flutter::TaskRunners task_runners( |
| 288 | + thread_label_, // Dart thread labels |
| 289 | + fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform |
| 290 | + thread_host_.gpu_thread->GetTaskRunner(), // gpu |
| 291 | + thread_host_.ui_thread->GetTaskRunner(), // ui |
| 292 | + thread_host_.io_thread->GetTaskRunner() // io |
| 293 | + ); |
| 294 | + |
277 | 295 | // Setup the callback that will instantiate the rasterizer. |
278 | 296 | flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer; |
279 | 297 | #if defined(LEGACY_FUCHSIA_EMBEDDER) |
@@ -454,12 +472,6 @@ Engine::Engine(Delegate& delegate, |
454 | 472 |
|
455 | 473 | Engine::~Engine() { |
456 | 474 | shell_.reset(); |
457 | | - for (auto& thread : threads_) { |
458 | | - thread.Quit(); |
459 | | - } |
460 | | - for (auto& thread : threads_) { |
461 | | - thread.Join(); |
462 | | - } |
463 | 475 | } |
464 | 476 |
|
465 | 477 | std::optional<uint32_t> Engine::GetEngineReturnCode() const { |
|
0 commit comments