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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gl/SkNativeGLContext.h" 8 #include "gl/SkNativeGLContext.h"
9 9
10 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { 10 SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 const GrGLInterface* SkNativeGLContext::createGLContext() { 54 const GrGLInterface* SkNativeGLContext::createGLContext() {
55 static const EGLint kEGLContextAttribsForOpenGL[] = { 55 static const EGLint kEGLContextAttribsForOpenGL[] = {
56 EGL_NONE 56 EGL_NONE
57 }; 57 };
58 58
59 static const EGLint kEGLContextAttribsForOpenGLES[] = { 59 static const EGLint kEGLContextAttribsForOpenGLES[] = {
60 EGL_CONTEXT_CLIENT_VERSION, 2, 60 EGL_CONTEXT_CLIENT_VERSION, 2,
61 EGL_NONE 61 EGL_NONE
62 }; 62 };
63 63
64 // Try first for OpenGL, then fall back to OpenGL ES. 64 static const struct {
65 EGLint renderableTypeBit = EGL_OPENGL_BIT; 65 const EGLint* fContextAttribs;
66 const EGLint* contextAttribs = kEGLContextAttribsForOpenGL; 66 EGLenum fAPI;
67 EGLBoolean apiBound = eglBindAPI(EGL_OPENGL_API); 67 EGLint fRenderableTypeBit;
68 GrGLBinding fBinding;
69 } kAPIs[] = {
70 { // OpenGL
71 kEGLContextAttribsForOpenGL,
robertphillips 2013/09/06 18:30:40 Shouldn't this be EGL_OPENGL_BIT?
bsalomon 2013/09/06 18:47:36 yes, nice catch.
72 EGL_OPENGL_ES_API,
73 EGL_OPENGL_BIT,
74 kDesktop_GrGLBinding
75 },
76 { // OpenGL ES. This seems to work for both ES2 and 3 (when available) .
77 kEGLContextAttribsForOpenGLES,
78 EGL_OPENGL_ES_API,
79 EGL_OPENGL_ES2_BIT,
80 kES_GrGLBinding
81 },
82 };
68 83
69 if (!apiBound) { 84 const GrGLInterface* interface = NULL;
70 apiBound = eglBindAPI(EGL_OPENGL_ES_API);
71 renderableTypeBit = EGL_OPENGL_ES2_BIT;
72 contextAttribs = kEGLContextAttribsForOpenGLES;
73 }
74 85
75 if (!apiBound) { 86 for (size_t api = 0; NULL == interface && api < SK_ARRAY_COUNT(kAPIs); ++api ) {
robertphillips 2013/09/06 18:30:40 Does the Display setting need to be inside the loo
bsalomon 2013/09/06 18:47:36 Yes, only because destroyContext(), called below,
76 return NULL;
77 }
78
79 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); 87 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
80 88
81 EGLint majorVersion; 89 EGLint majorVersion;
82 EGLint minorVersion; 90 EGLint minorVersion;
83 eglInitialize(fDisplay, &majorVersion, &minorVersion); 91 eglInitialize(fDisplay, &majorVersion, &minorVersion);
84 92
85 EGLint numConfigs; 93 #if 0
86 const EGLint configAttribs[] = { 94 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR));
87 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 95 SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS));
88 EGL_RENDERABLE_TYPE, renderableTypeBit, 96 SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION));
89 EGL_RED_SIZE, 8, 97 SkDebugf("EXTENSIONS %s\n", eglQueryString(fDisplay, EGL_EXTENSIONS));
90 EGL_GREEN_SIZE, 8, 98 #endif
91 EGL_BLUE_SIZE, 8,
92 EGL_ALPHA_SIZE, 8,
93 EGL_NONE
94 };
95 99
96 EGLConfig surfaceConfig; 100 if (!eglBindAPI(kAPIs[api].fAPI)) {
97 if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs )) { 101 continue;
98 SkDebugf("eglChooseConfig failed.\n"); 102 }
99 return NULL;
100 }
101 103
102 fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs); 104 EGLint numConfigs;
103 if (EGL_NO_CONTEXT == fContext) { 105 const EGLint configAttribs[] = {
104 SkDebugf("eglCreateContext failed.\n"); 106 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
105 return NULL; 107 EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit,
106 } 108 EGL_RED_SIZE, 8,
109 EGL_GREEN_SIZE, 8,
110 EGL_BLUE_SIZE, 8,
111 EGL_ALPHA_SIZE, 8,
112 EGL_NONE
113 };
107 114
108 static const EGLint kSurfaceAttribs[] = { 115 EGLConfig surfaceConfig;
109 EGL_WIDTH, 1, 116 if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numCon figs)) {
110 EGL_HEIGHT, 1, 117 SkDebugf("eglChooseConfig failed. EGL Error: 0x%08x\n", eglGetError( ));
robertphillips 2013/09/06 18:30:40 Not continue?
bsalomon 2013/09/06 18:47:36 Done.
111 EGL_NONE 118 return NULL;
112 }; 119 }
113 120
114 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttribs) ; 121 fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, kAPIs[api].fC ontextAttribs);
115 if (EGL_NO_SURFACE == fSurface) { 122 if (EGL_NO_CONTEXT == fContext) {
116 SkDebugf("eglCreatePbufferSurface failed.\n"); 123 SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetErro r());
117 this->destroyGLContext(); 124 continue;
118 return NULL; 125 }
119 }
120 126
121 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { 127 static const EGLint kSurfaceAttribs[] = {
122 SkDebugf("eglMakeCurrent failed.\n"); 128 EGL_WIDTH, 1,
123 this->destroyGLContext(); 129 EGL_HEIGHT, 1,
124 return NULL; 130 EGL_NONE
125 } 131 };
126 132
127 const GrGLInterface* interface = GrGLCreateNativeInterface(); 133 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttr ibs);
128 if (!interface) { 134 if (EGL_NO_SURFACE == fSurface) {
129 SkDebugf("Failed to create gl interface.\n"); 135 SkDebugf("eglCreatePbufferSurface failed. EGL Error: 0x%08x\n", eglG etError());
130 this->destroyGLContext(); 136 this->destroyGLContext();
131 return NULL; 137 continue;
138 }
139
140 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
141 SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError( ));
142 this->destroyGLContext();
143 continue;
144 }
145
146 interface = GrGLCreateNativeInterface();
147 if (NULL == interface) {
148 SkDebugf("Failed to create gl interface.\n");
149 this->destroyGLContext();
150 continue;
151 }
152
153 if (!interface->validate(kAPIs[api].fBinding)) {
154 interface->unref();
155 interface = NULL;
156 this->destroyGLContext();
157 }
132 } 158 }
133 159
134 return interface; 160 return interface;
135 } 161 }
136 162
137 void SkNativeGLContext::makeCurrent() const { 163 void SkNativeGLContext::makeCurrent() const {
138 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { 164 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
139 SkDebugf("Could not set the context.\n"); 165 SkDebugf("Could not set the context.\n");
140 } 166 }
141 } 167 }
OLDNEW
« 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