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(GrGLStandard forcedGpuAP
I) { | 69 const GrGLInterface* SkNativeGLContext::createGLContext() { |
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 | |
192 // Check for the GLX_ARB_create_context extension string and the function. | 190 // Check for the GLX_ARB_create_context extension string and the function. |
193 // If either is not present, use GLX 1.3 context creation method. | 191 // If either is not present, use GLX 1.3 context creation method. |
| 192 if (!gluCheckExtension( |
| 193 reinterpret_cast<const GLubyte*>("GLX_ARB_create_context") |
| 194 , reinterpret_cast<const GLubyte*>(glxExts))) |
| 195 { |
| 196 //SkDebugf("GLX_ARB_create_context not found." |
| 197 // " Using old-style GLX context.\n"); |
| 198 #ifdef GLX_1_3 |
| 199 fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True
); |
| 200 #else |
| 201 fContext = glXCreateContext(fDisplay, vi, 0, True); |
| 202 #endif |
194 | 203 |
195 if (!gluCheckExtension(reinterpret_cast<const GLubyte*>("GLX_ARB_create_cont
ext"), | |
196 reinterpret_cast<const GLubyte*>(glxExts))) { | |
197 if (kGLES_GrGLStandard != forcedGpuAPI) { | |
198 #ifdef GLX_1_3 | |
199 fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0,
True); | |
200 #else | |
201 fContext = glXCreateContext(fDisplay, vi, 0, True); | |
202 #endif | |
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 |
208 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = | 209 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = |
209 (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte*
)"glXCreateContextAttribsARB"); | 210 (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte*
)"glXCreateContextAttribsARB"); |
210 | 211 int context_attribs[] = { |
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, |
214 None | 215 None |
215 }; | 216 }; |
216 static const int context_attribs_gl_fallback[] = { | 217 fContext = glXCreateContextAttribsARB( |
217 GLX_CONTEXT_MAJOR_VERSION_ARB, 1, | 218 fDisplay, bestFbc, 0, True, context_attribs |
218 GLX_CONTEXT_MINOR_VERSION_ARB, 0, | 219 ); |
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 }; | |
227 | 220 |
228 if (kGLES_GrGLStandard == forcedGpuAPI) { | 221 // Sync to ensure any errors generated are processed. |
229 if (gluCheckExtension( | 222 XSync(fDisplay, False); |
230 reinterpret_cast<const GLubyte*>("GLX_EXT_create_context_es2
_profile"), | 223 if (!ctxErrorOccurred && fContext) { |
231 reinterpret_cast<const GLubyte*>(glxExts))) { | 224 //SkDebugf( "Created GL 3.0 context.\n" ); |
232 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True
, | |
233 context_attribs_gles); | |
234 } | |
235 } else { | 225 } else { |
236 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True, co
ntext_attribs_gl); | 226 // Couldn't create GL 3.0 context. |
| 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. |
237 | 231 |
238 // Sync to ensure any errors generated are processed. | 232 // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 |
239 XSync(fDisplay, False); | 233 context_attribs[1] = 1; |
240 if (ctxErrorOccurred || !fContext) { | 234 // GLX_CONTEXT_MINOR_VERSION_ARB = 0 |
241 // Couldn't create GL 3.0 context. | 235 context_attribs[3] = 0; |
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. | |
246 | 236 |
247 ctxErrorOccurred = false; | 237 ctxErrorOccurred = false; |
248 | 238 |
249 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True
, | 239 //SkDebugf("Failed to create GL 3.0 context." |
250 context_attribs_gl_fallbac
k); | 240 // " Using old-style GLX context.\n"); |
251 } | 241 fContext = glXCreateContextAttribsARB( |
| 242 fDisplay, bestFbc, 0, True, context_attribs |
| 243 ); |
252 } | 244 } |
253 } | 245 } |
254 #endif | 246 #endif |
255 | 247 |
256 // Sync to ensure any errors generated are processed. | 248 // Sync to ensure any errors generated are processed. |
257 XSync(fDisplay, False); | 249 XSync(fDisplay, False); |
258 | 250 |
259 // Restore the original error handler | 251 // Restore the original error handler |
260 XSetErrorHandler(oldHandler); | 252 XSetErrorHandler(oldHandler); |
261 | 253 |
(...skipping 28 matching lines...) Expand all Loading... |
290 | 282 |
291 void SkNativeGLContext::makeCurrent() const { | 283 void SkNativeGLContext::makeCurrent() const { |
292 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { | 284 if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { |
293 SkDebugf("Could not set the context.\n"); | 285 SkDebugf("Could not set the context.\n"); |
294 } | 286 } |
295 } | 287 } |
296 | 288 |
297 void SkNativeGLContext::swapBuffers() const { | 289 void SkNativeGLContext::swapBuffers() const { |
298 glXSwapBuffers(fDisplay, fGlxPixmap); | 290 glXSwapBuffers(fDisplay, fGlxPixmap); |
299 } | 291 } |
OLD | NEW |