112 reactor_worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
113 display_(std::move(display)) {
114 if (!display_ || !display_->IsValid()) {
115 FML_LOG(ERROR) <<
"Could not create context with invalid EGL display.";
116 return;
117 }
118
125
127 std::unique_ptr<impeller::egl::Config> onscreen_config =
128 display_->ChooseConfig(desc);
129
130 if (!onscreen_config) {
132 onscreen_config = display_->ChooseConfig(desc);
133 }
134
135 if (!onscreen_config) {
136
138 onscreen_config = display_->ChooseConfig(desc);
139 if (onscreen_config) {
140 FML_LOG(INFO) <<
"Warning: This device doesn't support MSAA for onscreen "
141 "framebuffers. Falling back to a single sample.";
142 } else {
143 FML_LOG(ERROR) <<
"Could not choose onscreen config.";
144 return;
145 }
146 }
147
149 auto offscreen_config = display_->ChooseConfig(desc);
150 if (!offscreen_config) {
151 FML_LOG(ERROR) <<
"Could not choose offscreen config.";
152 return;
153 }
154
155 auto onscreen_context = display_->CreateContext(*onscreen_config, nullptr);
156 if (!onscreen_context) {
157 FML_LOG(ERROR) <<
"Could not create onscreen context.";
158 return;
159 }
160
161 auto offscreen_context =
162 display_->CreateContext(*offscreen_config, onscreen_context.get());
163 if (!offscreen_context) {
164 FML_LOG(ERROR) <<
"Could not create offscreen context.";
165 return;
166 }
167
168
169
170 auto offscreen_surface =
171 display_->CreatePixelBufferSurface(*offscreen_config, 1u, 1u);
172 if (!offscreen_context->MakeCurrent(*offscreen_surface)) {
173 FML_LOG(ERROR) <<
"Could not make offscreen context current.";
174 return;
175 }
176
177 auto impeller_context =
179
180 if (!impeller_context) {
181 FML_LOG(ERROR) <<
"Could not create Impeller context.";
182 return;
183 }
184
185 if (!offscreen_context->ClearCurrent()) {
186 FML_LOG(ERROR) <<
"Could not clear offscreen context.";
187 return;
188 }
189
191 [worker =
192 reactor_worker_](impeller::egl ::Context::LifecycleEvent event) {
193 switch (event) {
195 worker->SetReactionsAllowedOnCurrentThread(true);
196 break;
198 worker->SetReactionsAllowedOnCurrentThread(false);
199 break;
200 }
201 };
202 if (!onscreen_context->AddLifecycleListener(listener).has_value() ||
203 !offscreen_context->AddLifecycleListener(listener).has_value()) {
204 FML_LOG(ERROR) <<
"Could not add lifecycle listeners";
205 }
206
207 onscreen_config_ = std::move(onscreen_config);
208 offscreen_config_ = std::move(offscreen_config);
209 onscreen_context_ = std::move(onscreen_context);
210 offscreen_context_ = std::move(offscreen_context);
212
213 is_valid_ = true;
214}
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)