OLD | NEW |
---|---|
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 #include <GL/glu.h> | 10 #include <GL/glu.h> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 if (fPixmap) { | 59 if (fPixmap) { |
60 XFreePixmap(fDisplay, fPixmap); | 60 XFreePixmap(fDisplay, fPixmap); |
61 fPixmap = 0; | 61 fPixmap = 0; |
62 } | 62 } |
63 | 63 |
64 XCloseDisplay(fDisplay); | 64 XCloseDisplay(fDisplay); |
65 fDisplay = NULL; | 65 fDisplay = NULL; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 const GrGLInterface* SkNativeGLContext::createGLContext() { | 69 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedStand ard) { |
70 fDisplay = XOpenDisplay(0); | 70 fDisplay = XOpenDisplay(0); |
71 | 71 |
72 if (!fDisplay) { | 72 if (!fDisplay) { |
73 SkDebugf("Failed to open X display.\n"); | 73 SkDebugf("Failed to open X display.\n"); |
74 this->destroyGLContext(); | 74 this->destroyGLContext(); |
75 return NULL; | 75 return NULL; |
76 } | 76 } |
77 | 77 |
78 // Get a matching FB config | 78 // Get a matching FB config |
79 static int visual_attribs[] = { | 79 static int visual_attribs[] = { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 // error handler, so be sure to guard against other threads issuing | 180 // error handler, so be sure to guard against other threads issuing |
181 // X commands while this code is running. | 181 // X commands while this code is running. |
182 ctxErrorOccurred = false; | 182 ctxErrorOccurred = false; |
183 int (*oldHandler)(Display*, XErrorEvent*) = | 183 int (*oldHandler)(Display*, XErrorEvent*) = |
184 XSetErrorHandler(&ctxErrorHandler); | 184 XSetErrorHandler(&ctxErrorHandler); |
185 | 185 |
186 // Get the default screen's GLX extension list | 186 // Get the default screen's GLX extension list |
187 const char *glxExts = glXQueryExtensionsString( | 187 const char *glxExts = glXQueryExtensionsString( |
188 fDisplay, DefaultScreen(fDisplay) | 188 fDisplay, DefaultScreen(fDisplay) |
189 ); | 189 ); |
190 | |
191 | |
190 // Check for the GLX_ARB_create_context extension string and the function. | 192 // Check for the GLX_ARB_create_context extension string and the function. |
191 // If either is not present, use GLX 1.3 context creation method. | 193 // If either is not present, use GLX 1.3 context creation method. |
192 if (!gluCheckExtension( | 194 |
193 reinterpret_cast<const GLubyte*>("GLX_ARB_create_context") | 195 if (!gluCheckExtension(reinterpret_cast<const GLubyte*>("GLX_ARB_create_cont ext"), |
194 , reinterpret_cast<const GLubyte*>(glxExts))) | 196 reinterpret_cast<const GLubyte*>(glxExts))) { |
195 { | 197 if (kGLES_GrGLStandard != forcedStandard) { |
196 //SkDebugf("GLX_ARB_create_context not found." | |
197 // " Using old-style GLX context.\n"); | |
198 #ifdef GLX_1_3 | 198 #ifdef GLX_1_3 |
199 fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True ); | 199 fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True); |
200 #else | 200 #else |
201 fContext = glXCreateContext(fDisplay, vi, 0, True); | 201 fContext = glXCreateContext(fDisplay, vi, 0, True); |
202 #endif | 202 #endif |
203 | 203 } |
204 } | 204 } |
205 #ifdef GLX_1_3 | 205 #ifdef GLX_1_3 |
206 else { | 206 else { |
207 //SkDebugf("Creating context.\n"); | 207 //SkDebugf("Creating context.\n"); |
208 | |
209 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = | 208 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = |
210 (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte* )"glXCreateContextAttribsARB"); | 209 (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte* )"glXCreateContextAttribsARB"); |
211 int context_attribs[] = { | 210 |
211 static const int context_attribs_gl[] = { | |
212 GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | 212 GLX_CONTEXT_MAJOR_VERSION_ARB, 3, |
213 GLX_CONTEXT_MINOR_VERSION_ARB, 0, | 213 GLX_CONTEXT_MINOR_VERSION_ARB, 0, |
214 //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ ARB, | |
215 None | 214 None |
216 }; | 215 }; |
217 fContext = glXCreateContextAttribsARB( | 216 static const int context_attribs_gl_fallback[] = { |
robertphillips
2014/06/09 14:31:05
Shouldn't this value be '1'?
Kimmo Kinnunen
2014/06/16 12:36:40
Done. (sorry..)
| |
218 fDisplay, bestFbc, 0, True, context_attribs | 217 GLX_CONTEXT_MAJOR_VERSION_ARB, 3, |
219 ); | 218 GLX_CONTEXT_MINOR_VERSION_ARB, 0, |
219 None | |
220 }; | |
221 static const int context_attribs_gles[] = { | |
222 GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | |
223 GLX_CONTEXT_MINOR_VERSION_ARB, 0, | |
224 GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT, | |
225 None | |
226 }; | |
220 | 227 |
221 // Sync to ensure any errors generated are processed. | 228 if (kGLES_GrGLStandard == forcedStandard) { |
222 XSync(fDisplay, False); | 229 if (gluCheckExtension( |
223 if (!ctxErrorOccurred && fContext) { | 230 reinterpret_cast<const GLubyte*>("GLX_EXT_create_context_es2 _profile"), |
224 //SkDebugf( "Created GL 3.0 context.\n" ); | 231 reinterpret_cast<const GLubyte*>(glxExts))) { |
232 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True , | |
233 context_attribs_gles); | |
234 } | |
225 } else { | 235 } else { |
226 // Couldn't create GL 3.0 context. | 236 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True, co ntext_attribs_gl); |
227 // Fall back to old-style 2.x context. | |
228 // When a context version below 3.0 is requested, | |
229 // implementations will return the newest context version compatible | |
230 // with OpenGL versions less than version 3.0. | |
231 | 237 |
232 // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 | 238 // Sync to ensure any errors generated are processed. |
233 context_attribs[1] = 1; | 239 XSync(fDisplay, False); |
234 // GLX_CONTEXT_MINOR_VERSION_ARB = 0 | 240 if (ctxErrorOccurred || !fContext) { |
235 context_attribs[3] = 0; | 241 // Couldn't create GL 3.0 context. |
242 // Fall back to old-style 2.x context. | |
243 // When a context version below 3.0 is requested, | |
244 // implementations will return the newest context version | |
245 // compatible with OpenGL versions less than version 3.0. | |
236 | 246 |
237 ctxErrorOccurred = false; | 247 ctxErrorOccurred = false; |
238 | 248 |
239 //SkDebugf("Failed to create GL 3.0 context." | 249 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True , |
240 // " Using old-style GLX context.\n"); | 250 context_attribs_gl_fallbac k); |
241 fContext = glXCreateContextAttribsARB( | 251 } |
242 fDisplay, bestFbc, 0, True, context_attribs | |
243 ); | |
244 } | 252 } |
245 } | 253 } |
246 #endif | 254 #endif |
247 | 255 |
248 // Sync to ensure any errors generated are processed. | 256 // Sync to ensure any errors generated are processed. |
249 XSync(fDisplay, False); | 257 XSync(fDisplay, False); |
250 | 258 |
251 // Restore the original error handler | 259 // Restore the original error handler |
252 XSetErrorHandler(oldHandler); | 260 XSetErrorHandler(oldHandler); |
253 | 261 |
(...skipping 28 matching lines...) Expand all Loading... | |
282 | 290 |
283 void SkNativeGLContext::makeCurrent() const { | 291 void SkNativeGLContext::makeCurrent() const { |
284 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { | 292 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { |
285 SkDebugf("Could not set the context.\n"); | 293 SkDebugf("Could not set the context.\n"); |
286 } | 294 } |
287 } | 295 } |
288 | 296 |
289 void SkNativeGLContext::swapBuffers() const { | 297 void SkNativeGLContext::swapBuffers() const { |
290 glXSwapBuffers(fDisplay, fGlxPixmap); | 298 glXSwapBuffers(fDisplay, fGlxPixmap); |
291 } | 299 } |
OLD | NEW |