Add extra safety check to the EGL context setup.
Adds a check to make sure eglChooseConfig actually
found a valid config. Besides checking for EGL errors,
we also have to handle the case when no matching configs
are found, i.e when num_config is 0.
BUG=skia:
Review URL: https://codereview.chromium.org/762113003
diff --git a/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp b/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp
index 6fc8f48..1974197 100644
--- a/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp
+++ b/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp
@@ -87,7 +87,7 @@
continue;
}
- EGLint numConfigs;
+ EGLint numConfigs = 0;
const EGLint configAttribs[] = {
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit,
@@ -104,6 +104,11 @@
continue;
}
+ if (0 == numConfigs) {
+ SkDebugf("No suitable EGL config found.\n");
+ continue;
+ }
+
fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, kAPIs[api].fContextAttribs);
if (EGL_NO_CONTEXT == fContext) {
SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetError());