Skip to content

Commit c6f5e87

Browse files
committed
Make sure a valid EGL context can be created.
1 parent 8a8a9ab commit c6f5e87

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

src/flutter_application.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ FlutterApplication::FlutterApplication() {
6666
&FlutterApplication::PresentSurface;
6767

6868
// TODO: Pipe this in through command line args.
69-
#define MY_PROJECT \
70-
"/home/buzzy/VersionControlled/flutter/examples/flutter_gallery"
69+
#define MY_PROJECT \
70+
"/usr/local/google/home/chinmaygarde/VersionControlled/flutter/examples/" \
71+
"flutter_gallery/build/flutter_assets"
7172

7273
std::vector<const char*> engine_command_line_args = {
7374
"--disable-observatory", //

src/macros.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
#define __FLWAY_LINE_PREFIX << __FILE__ << ":" << __LINE__ << ": "
1919
#define FLWAY_LOG std::cout << "LOG: " __FLWAY_LINE_PREFIX
2020
#define FLWAY_ERROR std::cerr << "ERROR: " __FLWAY_LINE_PREFIX
21+
#define FLWAY_WIP \
22+
std::cerr << "Work In Progress. Aborting." << std::endl; \
23+
abort();

src/wayland_display.cc

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bool WaylandDisplay::Run() {
126126
return false;
127127
}
128128

129-
abort();
129+
FLWAY_WIP;
130130

131131
return true;
132132
}
@@ -215,8 +215,12 @@ bool WaylandDisplay::SetupEGL() {
215215
return false;
216216
}
217217

218-
EGLint attributes[] = {
219-
// clang-format off
218+
EGLConfig egl_config = nullptr;
219+
220+
// Choose an EGL config to use for the surface and context.
221+
{
222+
EGLint attribs[] = {
223+
// clang-format off
220224
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
221225
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
222226
EGL_RED_SIZE, 8,
@@ -226,36 +230,53 @@ bool WaylandDisplay::SetupEGL() {
226230
EGL_DEPTH_SIZE, 0,
227231
EGL_STENCIL_SIZE, 0,
228232
EGL_NONE, // termination sentinel
229-
// clang-format on
230-
};
233+
// clang-format on
234+
};
231235

232-
EGLint config_count = 0;
233-
EGLConfig egl_config = nullptr;
236+
EGLint config_count = 0;
234237

235-
if (eglChooseConfig(egl_display_, attributes, &egl_config, 1,
236-
&config_count) != EGL_TRUE) {
237-
LogLastEGLError();
238-
FLWAY_ERROR << "Error when attempting to choose an EGL surface config."
239-
<< std::endl;
240-
return false;
238+
if (eglChooseConfig(egl_display_, attribs, &egl_config, 1, &config_count) !=
239+
EGL_TRUE) {
240+
LogLastEGLError();
241+
FLWAY_ERROR << "Error when attempting to choose an EGL surface config."
242+
<< std::endl;
243+
return false;
244+
}
245+
246+
if (config_count == 0 || egl_config == nullptr) {
247+
LogLastEGLError();
248+
FLWAY_ERROR << "No matching configs." << std::endl;
249+
return false;
250+
}
241251
}
242252

243-
if (config_count == 0 || egl_config == nullptr) {
244-
LogLastEGLError();
245-
FLWAY_ERROR << "No matching configs." << std::endl;
246-
return false;
253+
// Create an EGL window surface with the matched config.
254+
{
255+
const EGLint attribs[] = {EGL_NONE};
256+
257+
egl_surface_ =
258+
eglCreateWindowSurface(egl_display_, egl_config, window_, attribs);
259+
260+
if (surface_ == EGL_NO_SURFACE) {
261+
LogLastEGLError();
262+
FLWAY_ERROR << "EGL surface was null during surface selection."
263+
<< std::endl;
264+
return false;
265+
}
247266
}
248267

249-
const EGLint attribs[] = {EGL_NONE};
268+
// Create an EGL context with the match config.
269+
{
270+
const EGLint attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
250271

251-
egl_surface_ =
252-
eglCreateWindowSurface(egl_display_, egl_config, window_, attribs);
272+
egl_context_ = eglCreateContext(egl_display_, egl_config,
273+
nullptr /* share group */, attribs);
253274

254-
if (surface_ == EGL_NO_SURFACE) {
255-
LogLastEGLError();
256-
FLWAY_ERROR << "EGL surface was null during surface selection."
257-
<< std::endl;
258-
return false;
275+
if (egl_context_ == EGL_NO_CONTEXT) {
276+
LogLastEGLError();
277+
FLWAY_ERROR << "Could not create an onscreen context." << std::endl;
278+
return false;
279+
}
259280
}
260281

261282
return true;

src/wayland_display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class WaylandDisplay {
4343
wl_egl_window* window_ = nullptr;
4444
EGLDisplay egl_display_ = EGL_NO_DISPLAY;
4545
EGLSurface egl_surface_ = nullptr;
46+
EGLContext egl_context_ = EGL_NO_CONTEXT;
4647

4748
bool SetupEGL();
4849

0 commit comments

Comments
 (0)