@@ -50,6 +50,18 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
5050 auto shell =
5151 std::unique_ptr<Shell>(new Shell (std::move (vm), task_runners, settings));
5252
53+ // Create the rasterizer on the GPU thread.
54+ std::promise<std::unique_ptr<Rasterizer>> rasterizer_promise;
55+ auto rasterizer_future = rasterizer_promise.get_future ();
56+ fml::TaskRunner::RunNowOrPostTask (
57+ task_runners.GetGPUTaskRunner (), [&rasterizer_promise, //
58+ on_create_rasterizer, //
59+ shell = shell.get () //
60+ ]() {
61+ TRACE_EVENT0 (" flutter" , " ShellSetupGPUSubsystem" );
62+ rasterizer_promise.set_value (on_create_rasterizer (*shell));
63+ });
64+
5365 // Create the platform view on the platform thread (this thread).
5466 auto platform_view = on_create_platform_view (*shell.get ());
5567 if (!platform_view || !platform_view->GetWeakPtr ()) {
@@ -67,58 +79,41 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
6779 // first because it has state that the other subsystems depend on. It must
6880 // first be booted and the necessary references obtained to initialize the
6981 // other subsystems.
70- fml::AutoResetWaitableEvent io_latch;
71- std::unique_ptr<ShellIOManager> io_manager;
82+ std::promise<std::unique_ptr<ShellIOManager>> io_manager_promise;
83+ auto io_manager_future = io_manager_promise.get_future ();
84+ std::promise<fml::WeakPtr<ShellIOManager>> weak_io_manager_promise;
85+ auto weak_io_manager_future = weak_io_manager_promise.get_future ();
7286 auto io_task_runner = shell->GetTaskRunners ().GetIOTaskRunner ();
7387 fml::TaskRunner::RunNowOrPostTask (
7488 io_task_runner,
75- [&io_latch, //
76- &io_manager, //
77- & platform_view, //
78- io_task_runner //
89+ [&io_manager_promise, //
90+ &weak_io_manager_promise, //
91+ platform_view = platform_view-> GetWeakPtr () , //
92+ io_task_runner //
7993 ]() {
8094 TRACE_EVENT0 (" flutter" , " ShellSetupIOSubsystem" );
81- io_manager = std::make_unique<ShellIOManager>(
95+ auto io_manager = std::make_unique<ShellIOManager>(
8296 platform_view->CreateResourceContext (), io_task_runner);
83- io_latch.Signal ();
97+ weak_io_manager_promise.set_value (io_manager->GetWeakPtr ());
98+ io_manager_promise.set_value (std::move (io_manager));
8499 });
85- io_latch.Wait ();
86-
87- // Create the rasterizer on the GPU thread.
88- fml::AutoResetWaitableEvent gpu_latch;
89- std::unique_ptr<Rasterizer> rasterizer;
90- fml::TaskRunner::RunNowOrPostTask (
91- task_runners.GetGPUTaskRunner (), [&gpu_latch, //
92- &rasterizer, //
93- on_create_rasterizer, //
94- shell = shell.get () //
95- ]() {
96- TRACE_EVENT0 (" flutter" , " ShellSetupGPUSubsystem" );
97- if (auto new_rasterizer = on_create_rasterizer (*shell)) {
98- rasterizer = std::move (new_rasterizer);
99- }
100- gpu_latch.Signal ();
101- });
102-
103- gpu_latch.Wait ();
104100
105101 // Send dispatcher_maker to the engine constructor because shell won't have
106102 // platform_view set until Shell::Setup is called later.
107103 auto dispatcher_maker = platform_view->GetDispatcherMaker ();
108104
109105 // Create the engine on the UI thread.
110- fml::AutoResetWaitableEvent ui_latch ;
111- std::unique_ptr<Engine> engine ;
106+ std::promise<std::unique_ptr<Engine>> engine_promise ;
107+ auto engine_future = engine_promise. get_future () ;
112108 fml::TaskRunner::RunNowOrPostTask (
113109 shell->GetTaskRunners ().GetUITaskRunner (),
114- fml::MakeCopyable ([&ui_latch, //
115- &engine, //
110+ fml::MakeCopyable ([&engine_promise, //
116111 shell = shell.get (), //
117112 &dispatcher_maker, //
118113 isolate_snapshot = std::move (isolate_snapshot), //
119114 shared_snapshot = std::move (shared_snapshot), //
120115 vsync_waiter = std::move (vsync_waiter), //
121- io_manager = io_manager-> GetWeakPtr () //
116+ &weak_io_manager_future //
122117 ]() mutable {
123118 TRACE_EVENT0 (" flutter" , " ShellSetupUISubsystem" );
124119 const auto & task_runners = shell->GetTaskRunners ();
@@ -128,27 +123,23 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
128123 auto animator = std::make_unique<Animator>(*shell, task_runners,
129124 std::move (vsync_waiter));
130125
131- engine = std::make_unique<Engine>(*shell, //
132- dispatcher_maker, //
133- *shell-> GetDartVM (), //
134- std::move (isolate_snapshot), //
135- std::move (shared_snapshot), //
136- task_runners, //
137- shell-> GetSettings (), //
138- std::move (animator), //
139- std::move (io_manager) //
140- );
141- ui_latch. Signal ( );
126+ engine_promise. set_value ( std::make_unique<Engine>(
127+ *shell, //
128+ dispatcher_maker, //
129+ *shell-> GetDartVM (), //
130+ std::move (isolate_snapshot), //
131+ std::move (shared_snapshot), //
132+ task_runners, //
133+ shell-> GetSettings (), //
134+ std::move (animator), //
135+ weak_io_manager_future. get () //
136+ ) );
142137 }));
143138
144- ui_latch.Wait ();
145- // We are already on the platform thread. So there is no platform latch to
146- // wait on.
147-
148139 if (!shell->Setup (std::move (platform_view), //
149- std::move (engine), //
150- std::move (rasterizer), //
151- std::move (io_manager)) //
140+ engine_future. get (), //
141+ rasterizer_future. get (), //
142+ io_manager_future. get ()) //
152143 ) {
153144 return nullptr ;
154145 }
0 commit comments