OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string.h> | 5 #include <string.h> |
6 #include <GL/glx.h> | 6 #include <GL/glx.h> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "main.h" | 9 #include "main.h" |
10 #include "xlib_window.h" | 10 #include "xlib_window.h" |
11 | 11 |
12 static GLXContext glx_context = NULL; | 12 static GLXContext glx_context = NULL; |
13 static GLXFBConfig glx_fbconfig = NULL; | 13 static GLXFBConfig glx_fbconfig = NULL; |
14 | 14 |
15 #define F(fun, type) type fun = NULL; | 15 #define F(fun, type) type fun = NULL; |
16 LIST_PROC_FUNCTIONS(F) | 16 LIST_PROC_FUNCTIONS(F) |
17 #undef F | 17 #undef F |
| 18 PFNGLXSWAPINTERVALMESAPROC _glXSwapIntervalMESA = NULL; |
18 | 19 |
19 bool Init() { | 20 bool Init() { |
20 return XlibInit(); | 21 return XlibInit(); |
21 } | 22 } |
22 | 23 |
23 XVisualInfo* GetXVisual() { | 24 XVisualInfo* GetXVisual() { |
24 if (!glx_fbconfig) { | 25 if (!glx_fbconfig) { |
25 int screen = DefaultScreen(g_xlib_display); | 26 int screen = DefaultScreen(g_xlib_display); |
26 int attrib[] = { | 27 int attrib[] = { |
27 GLX_DOUBLEBUFFER, True, | 28 GLX_DOUBLEBUFFER, True, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 66 |
66 const GLubyte *str = glGetString(GL_EXTENSIONS); | 67 const GLubyte *str = glGetString(GL_EXTENSIONS); |
67 if (!str || !strstr(reinterpret_cast<const char *>(str), | 68 if (!str || !strstr(reinterpret_cast<const char *>(str), |
68 "GL_ARB_vertex_buffer_object")) | 69 "GL_ARB_vertex_buffer_object")) |
69 return false; | 70 return false; |
70 | 71 |
71 #define F(fun, type) fun = reinterpret_cast<type>( \ | 72 #define F(fun, type) fun = reinterpret_cast<type>( \ |
72 glXGetProcAddress(reinterpret_cast<const GLubyte *>(#fun))); | 73 glXGetProcAddress(reinterpret_cast<const GLubyte *>(#fun))); |
73 LIST_PROC_FUNCTIONS(F) | 74 LIST_PROC_FUNCTIONS(F) |
74 #undef F | 75 #undef F |
| 76 _glXSwapIntervalMESA = reinterpret_cast<PFNGLXSWAPINTERVALMESAPROC>( |
| 77 glXGetProcAddress(reinterpret_cast<const GLubyte *>( |
| 78 "glXSwapIntervalMESA"))); |
75 | 79 |
76 return true; | 80 return true; |
77 } | 81 } |
78 | 82 |
79 void DestroyContext() { | 83 void DestroyContext() { |
80 glXMakeCurrent(g_xlib_display, 0, NULL); | 84 glXMakeCurrent(g_xlib_display, 0, NULL); |
81 glXDestroyContext(g_xlib_display, glx_context); | 85 glXDestroyContext(g_xlib_display, glx_context); |
82 } | 86 } |
83 | 87 |
84 void SwapBuffers() { | 88 void SwapBuffers() { |
85 glXSwapBuffers(g_xlib_display, g_xlib_window); | 89 glXSwapBuffers(g_xlib_display, g_xlib_window); |
86 } | 90 } |
87 | 91 |
88 bool SwapInterval(int interval) { | 92 bool SwapInterval(int interval) { |
89 return glXSwapIntervalSGI(interval) == 0; | 93 // Strictly, glXSwapIntervalSGI only allows interval > 0, whereas |
| 94 // glXSwapIntervalMESA allow 0 with the same semantics as eglSwapInterval. |
| 95 if (_glXSwapIntervalMESA) { |
| 96 return _glXSwapIntervalMESA(interval) == 0; |
| 97 } else { |
| 98 return glXSwapIntervalSGI(interval) == 0; |
| 99 } |
90 } | 100 } |
OLD | NEW |