114 reactor_worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
115 display_(std::move(display)),
116 io_task_runner_(std::move(io_task_runner)) {
117 if (!display_ || !display_->IsValid()) {
118 FML_LOG(ERROR) <<
"Could not create context with invalid EGL display.";
119 return;
120 }
121
128
130 std::unique_ptr<impeller::egl::Config> onscreen_config =
131 display_->ChooseConfig(desc);
132
133 if (!onscreen_config) {
135 onscreen_config = display_->ChooseConfig(desc);
136 }
137
138 if (!onscreen_config) {
139
141 onscreen_config = display_->ChooseConfig(desc);
142 if (onscreen_config) {
143 FML_LOG(INFO) <<
"Warning: This device doesn't support MSAA for onscreen "
144 "framebuffers. Falling back to a single sample.";
145 } else {
146 FML_LOG(ERROR) <<
"Could not choose onscreen config.";
147 return;
148 }
149 }
150
152 auto offscreen_config = display_->ChooseConfig(desc);
153 if (!offscreen_config) {
154 FML_LOG(ERROR) <<
"Could not choose offscreen config.";
155 return;
156 }
157
158 auto onscreen_context = display_->CreateContext(*onscreen_config, nullptr);
159 if (!onscreen_context) {
160 FML_LOG(ERROR) <<
"Could not create onscreen context.";
161 return;
162 }
163
164 auto offscreen_context =
165 display_->CreateContext(*offscreen_config, onscreen_context.get());
166 if (!offscreen_context) {
167 FML_LOG(ERROR) <<
"Could not create offscreen context.";
168 return;
169 }
170
171
172
173 auto offscreen_surface =
174 display_->CreatePixelBufferSurface(*offscreen_config, 1u, 1u);
175 if (!offscreen_context->MakeCurrent(*offscreen_surface)) {
176 FML_LOG(ERROR) <<
"Could not make offscreen context current.";
177 return;
178 }
179
181 reactor_worker_, enable_gpu_tracing, io_task_runner_);
182
183 if (!impeller_context) {
184 FML_LOG(ERROR) <<
"Could not create Impeller context.";
185 return;
186 }
187
188 if (!offscreen_context->ClearCurrent()) {
189 FML_LOG(ERROR) <<
"Could not clear offscreen context.";
190 return;
191 }
192
194 [worker =
195 reactor_worker_](impeller::egl ::Context::LifecycleEvent event) {
196 switch (event) {
198 worker->SetReactionsAllowedOnCurrentThread(true);
199 break;
201 worker->SetReactionsAllowedOnCurrentThread(false);
202 break;
203 }
204 };
205 if (!onscreen_context->AddLifecycleListener(listener).has_value() ||
206 !offscreen_context->AddLifecycleListener(listener).has_value()) {
207 FML_LOG(ERROR) <<
"Could not add lifecycle listeners";
208 }
209
210 onscreen_config_ = std::move(onscreen_config);
211 offscreen_config_ = std::move(offscreen_config);
212 onscreen_context_ = std::move(onscreen_context);
213 offscreen_context_ = std::move(offscreen_context);
215
216 is_valid_ = true;
217}
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()
AndroidContext(AndroidRenderingAPI rendering_api)
void SetImpellerContext(const std::shared_ptr< impeller::Context > &impeller_context)
std::function< void(LifecycleEvent)> LifecycleListener
#define FML_LOG(severity)