@@ -50,6 +50,18 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
50
50
auto shell =
51
51
std::unique_ptr<Shell>(new Shell (std::move (vm), task_runners, settings));
52
52
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
+
53
65
// Create the platform view on the platform thread (this thread).
54
66
auto platform_view = on_create_platform_view (*shell.get ());
55
67
if (!platform_view || !platform_view->GetWeakPtr ()) {
@@ -67,58 +79,41 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
67
79
// first because it has state that the other subsystems depend on. It must
68
80
// first be booted and the necessary references obtained to initialize the
69
81
// 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 ();
72
86
auto io_task_runner = shell->GetTaskRunners ().GetIOTaskRunner ();
73
87
fml::TaskRunner::RunNowOrPostTask (
74
88
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 //
79
93
]() {
80
94
TRACE_EVENT0 (" flutter" , " ShellSetupIOSubsystem" );
81
- io_manager = std::make_unique<ShellIOManager>(
95
+ auto io_manager = std::make_unique<ShellIOManager>(
82
96
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));
84
99
});
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 ();
104
100
105
101
// Send dispatcher_maker to the engine constructor because shell won't have
106
102
// platform_view set until Shell::Setup is called later.
107
103
auto dispatcher_maker = platform_view->GetDispatcherMaker ();
108
104
109
105
// 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 () ;
112
108
fml::TaskRunner::RunNowOrPostTask (
113
109
shell->GetTaskRunners ().GetUITaskRunner (),
114
- fml::MakeCopyable ([&ui_latch, //
115
- &engine, //
110
+ fml::MakeCopyable ([&engine_promise, //
116
111
shell = shell.get (), //
117
112
&dispatcher_maker, //
118
113
isolate_snapshot = std::move (isolate_snapshot), //
119
114
shared_snapshot = std::move (shared_snapshot), //
120
115
vsync_waiter = std::move (vsync_waiter), //
121
- io_manager = io_manager-> GetWeakPtr () //
116
+ &weak_io_manager_future //
122
117
]() mutable {
123
118
TRACE_EVENT0 (" flutter" , " ShellSetupUISubsystem" );
124
119
const auto & task_runners = shell->GetTaskRunners ();
@@ -128,27 +123,23 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
128
123
auto animator = std::make_unique<Animator>(*shell, task_runners,
129
124
std::move (vsync_waiter));
130
125
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
+ ) );
142
137
}));
143
138
144
- ui_latch.Wait ();
145
- // We are already on the platform thread. So there is no platform latch to
146
- // wait on.
147
-
148
139
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 ()) //
152
143
) {
153
144
return nullptr ;
154
145
}
0 commit comments