Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1163)

Unified Diff: src/gpu/gl/android/SkNativeGLContext_android.cpp

Issue 23902015: Fallback to GLES context when GL context setup fails at any stage. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/android/SkNativeGLContext_android.cpp
===================================================================
--- src/gpu/gl/android/SkNativeGLContext_android.cpp (revision 11129)
+++ src/gpu/gl/android/SkNativeGLContext_android.cpp (working copy)
@@ -61,74 +61,100 @@
EGL_NONE
};
- // Try first for OpenGL, then fall back to OpenGL ES.
- EGLint renderableTypeBit = EGL_OPENGL_BIT;
- const EGLint* contextAttribs = kEGLContextAttribsForOpenGL;
- EGLBoolean apiBound = eglBindAPI(EGL_OPENGL_API);
+ static const struct {
+ const EGLint* fContextAttribs;
+ EGLenum fAPI;
+ EGLint fRenderableTypeBit;
+ GrGLBinding fBinding;
+ } kAPIs[] = {
+ { // OpenGL
+ kEGLContextAttribsForOpenGL,
+ EGL_OPENGL_API,
+ EGL_OPENGL_BIT,
+ kDesktop_GrGLBinding
+ },
+ { // OpenGL ES. This seems to work for both ES2 and 3 (when available).
+ kEGLContextAttribsForOpenGLES,
+ EGL_OPENGL_ES_API,
+ EGL_OPENGL_ES2_BIT,
+ kES_GrGLBinding
+ },
+ };
- if (!apiBound) {
- apiBound = eglBindAPI(EGL_OPENGL_ES_API);
- renderableTypeBit = EGL_OPENGL_ES2_BIT;
- contextAttribs = kEGLContextAttribsForOpenGLES;
- }
+ const GrGLInterface* interface = NULL;
- if (!apiBound) {
- return NULL;
- }
+ for (size_t api = 0; NULL == interface && api < SK_ARRAY_COUNT(kAPIs); ++api) {
+ fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ EGLint majorVersion;
+ EGLint minorVersion;
+ eglInitialize(fDisplay, &majorVersion, &minorVersion);
- EGLint majorVersion;
- EGLint minorVersion;
- eglInitialize(fDisplay, &majorVersion, &minorVersion);
+#if 0
+ SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR));
+ SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS));
+ SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION));
+ SkDebugf("EXTENSIONS %s\n", eglQueryString(fDisplay, EGL_EXTENSIONS));
+#endif
- EGLint numConfigs;
- const EGLint configAttribs[] = {
- EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
- EGL_RENDERABLE_TYPE, renderableTypeBit,
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_ALPHA_SIZE, 8,
- EGL_NONE
- };
+ if (!eglBindAPI(kAPIs[api].fAPI)) {
+ continue;
+ }
- EGLConfig surfaceConfig;
- if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs)) {
- SkDebugf("eglChooseConfig failed.\n");
- return NULL;
- }
+ EGLint numConfigs;
+ const EGLint configAttribs[] = {
+ EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
+ EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit,
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_NONE
+ };
- fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
- if (EGL_NO_CONTEXT == fContext) {
- SkDebugf("eglCreateContext failed.\n");
- return NULL;
- }
+ EGLConfig surfaceConfig;
+ if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs)) {
+ SkDebugf("eglChooseConfig failed. EGL Error: 0x%08x\n", eglGetError());
+ continue;
+ }
- static const EGLint kSurfaceAttribs[] = {
- EGL_WIDTH, 1,
- EGL_HEIGHT, 1,
- EGL_NONE
- };
+ fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, kAPIs[api].fContextAttribs);
+ if (EGL_NO_CONTEXT == fContext) {
+ SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetError());
+ continue;
+ }
- fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttribs);
- if (EGL_NO_SURFACE == fSurface) {
- SkDebugf("eglCreatePbufferSurface failed.\n");
- this->destroyGLContext();
- return NULL;
- }
+ static const EGLint kSurfaceAttribs[] = {
+ EGL_WIDTH, 1,
+ EGL_HEIGHT, 1,
+ EGL_NONE
+ };
- if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
- SkDebugf("eglMakeCurrent failed.\n");
- this->destroyGLContext();
- return NULL;
- }
+ fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttribs);
+ if (EGL_NO_SURFACE == fSurface) {
+ SkDebugf("eglCreatePbufferSurface failed. EGL Error: 0x%08x\n", eglGetError());
+ this->destroyGLContext();
+ continue;
+ }
- const GrGLInterface* interface = GrGLCreateNativeInterface();
- if (!interface) {
- SkDebugf("Failed to create gl interface.\n");
- this->destroyGLContext();
- return NULL;
+ if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
+ SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError());
+ this->destroyGLContext();
+ continue;
+ }
+
+ interface = GrGLCreateNativeInterface();
+ if (NULL == interface) {
+ SkDebugf("Failed to create gl interface.\n");
+ this->destroyGLContext();
+ continue;
+ }
+
+ if (!interface->validate(kAPIs[api].fBinding)) {
+ interface->unref();
+ interface = NULL;
+ this->destroyGLContext();
+ }
}
return interface;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698