OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 // This class implements the XWindowWrapper class. | 5 // This class implements the XWindowWrapper class. |
6 | 6 |
| 7 #include <dlfcn.h> |
| 8 |
7 #include "gpu/command_buffer/service/precompile.h" | 9 #include "gpu/command_buffer/service/precompile.h" |
8 #include "gpu/command_buffer/common/logging.h" | 10 #include "gpu/command_buffer/common/logging.h" |
9 #include "gpu/command_buffer/service/x_utils.h" | 11 #include "gpu/command_buffer/service/x_utils.h" |
10 | 12 |
11 namespace gpu { | 13 namespace gpu { |
12 | 14 |
| 15 // Some versions of NVIDIA's GL libGL.so include a broken version of |
| 16 // dlopen/dlsym, and so linking it into chrome breaks it. So we dynamically |
| 17 // load it, and use glew to dynamically resolve symbols. |
| 18 // See http://code.google.com/p/chromium/issues/detail?id=16800 |
| 19 |
| 20 static bool g_glew_initialized = false; |
| 21 |
13 bool XWindowWrapper::Initialize() { | 22 bool XWindowWrapper::Initialize() { |
| 23 if (!g_glew_initialized) { |
| 24 void* handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); |
| 25 if (!handle) { |
| 26 LOG(ERROR) << "Could not find libGL.so.1"; |
| 27 return false; |
| 28 } |
| 29 |
| 30 // Initializes context-independent parts of GLEW |
| 31 if (glxewInit() != GLEW_OK) { |
| 32 LOG(ERROR) << "GLXEW failed initialization"; |
| 33 return false; |
| 34 } |
| 35 g_glew_initialized = true; |
| 36 } |
14 XWindowAttributes attributes; | 37 XWindowAttributes attributes; |
15 XGetWindowAttributes(display_, window_, &attributes); | 38 XGetWindowAttributes(display_, window_, &attributes); |
16 XVisualInfo visual_info_template; | 39 XVisualInfo visual_info_template; |
17 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); | 40 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); |
18 int visual_info_count = 0; | 41 int visual_info_count = 0; |
19 XVisualInfo *visual_info_list = XGetVisualInfo(display_, VisualIDMask, | 42 XVisualInfo *visual_info_list = XGetVisualInfo(display_, VisualIDMask, |
20 &visual_info_template, | 43 &visual_info_template, |
21 &visual_info_count); | 44 &visual_info_count); |
22 DCHECK(visual_info_list); | 45 DCHECK(visual_info_list); |
23 DCHECK_GT(visual_info_count, 0); | 46 DCHECK_GT(visual_info_count, 0); |
24 context_ = 0; | 47 context_ = 0; |
25 for (int i = 0; i < visual_info_count; ++i) { | 48 for (int i = 0; i < visual_info_count; ++i) { |
26 context_ = glXCreateContext(display_, visual_info_list + i, 0, | 49 context_ = glXCreateContext(display_, visual_info_list + i, 0, |
27 True); | 50 True); |
28 if (context_) break; | 51 if (context_) break; |
29 } | 52 } |
30 XFree(visual_info_list); | 53 XFree(visual_info_list); |
31 if (!context_) { | 54 if (!context_) { |
32 DLOG(ERROR) << "Couldn't create GL context."; | 55 DLOG(ERROR) << "Couldn't create GL context."; |
33 return false; | 56 return false; |
34 } | 57 } |
| 58 if (!MakeCurrent()) { |
| 59 return false; |
| 60 } |
| 61 |
| 62 // Initializes context-dependent parts of GLEW |
| 63 if (glewInit() != GLEW_OK) { |
| 64 LOG(ERROR) << "GLEW failed initialization"; |
| 65 return false; |
| 66 } |
| 67 |
| 68 if (!glewIsSupported("GL_VERSION_2_0")) { |
| 69 LOG(ERROR) << "GL implementation doesn't support GL version 2.0"; |
| 70 return false; |
| 71 } |
| 72 |
35 return true; | 73 return true; |
36 } | 74 } |
37 | 75 |
38 bool XWindowWrapper::MakeCurrent() { | 76 bool XWindowWrapper::MakeCurrent() { |
39 if (glXMakeCurrent(display_, window_, context_) != True) { | 77 if (glXMakeCurrent(display_, window_, context_) != True) { |
40 glXDestroyContext(display_, context_); | 78 glXDestroyContext(display_, context_); |
41 context_ = 0; | 79 context_ = 0; |
42 DLOG(ERROR) << "Couldn't make context current."; | 80 DLOG(ERROR) << "Couldn't make context current."; |
43 return false; | 81 return false; |
44 } | 82 } |
(...skipping 10 matching lines...) Expand all Loading... |
55 glXDestroyContext(display_, context_); | 93 glXDestroyContext(display_, context_); |
56 context_ = 0; | 94 context_ = 0; |
57 } | 95 } |
58 } | 96 } |
59 | 97 |
60 void XWindowWrapper::SwapBuffers() { | 98 void XWindowWrapper::SwapBuffers() { |
61 glXSwapBuffers(display_, window_); | 99 glXSwapBuffers(display_, window_); |
62 } | 100 } |
63 | 101 |
64 } // namespace gpu | 102 } // namespace gpu |
OLD | NEW |