OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 extern "C" { | 5 extern "C" { |
6 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
7 } | 7 } |
8 | 8 |
9 #include "ui/gfx/gl/gl_context_glx.h" | 9 #include "ui/gfx/gl/gl_context_glx.h" |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" | 13 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" |
| 14 #include "ui/base/x/x11_util.h" |
| 15 #include "ui/base/x/x11_util_internal.h" |
14 #include "ui/gfx/gl/gl_bindings.h" | 16 #include "ui/gfx/gl/gl_bindings.h" |
15 #include "ui/gfx/gl/gl_implementation.h" | 17 #include "ui/gfx/gl/gl_implementation.h" |
16 #include "ui/gfx/gl/gl_surface_glx.h" | 18 #include "ui/gfx/gl/gl_surface_glx.h" |
17 | 19 |
| 20 #define CHECK_X_ERROR() do { \ |
| 21 CHECK(!ui::GetLastX11Error(gfx::GLSurfaceGLX::GetDisplay())); \ |
| 22 } while(0) |
| 23 |
18 namespace gfx { | 24 namespace gfx { |
19 | 25 |
20 namespace { | 26 namespace { |
21 | 27 |
22 // scoped_ptr functor for XFree(). Use as follows: | 28 // scoped_ptr functor for XFree(). Use as follows: |
23 // scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> foo(...); | 29 // scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> foo(...); |
24 // where "XVisualInfo" is any X type that is freed with XFree. | 30 // where "XVisualInfo" is any X type that is freed with XFree. |
25 class ScopedPtrXFree { | 31 class ScopedPtrXFree { |
26 public: | 32 public: |
27 void operator()(void* x) const { | 33 void operator()(void* x) const { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // in this case, since we will likely allocate our offscreen | 87 // in this case, since we will likely allocate our offscreen |
82 // contexts with this bit set and the onscreen contexts without, | 88 // contexts with this bit set and the onscreen contexts without, |
83 // and won't be able to put them in the same share group. | 89 // and won't be able to put them in the same share group. |
84 // Consider what to do here; force loss of all contexts and | 90 // Consider what to do here; force loss of all contexts and |
85 // reallocation without ARB_robustness? | 91 // reallocation without ARB_robustness? |
86 LOG(ERROR) << | 92 LOG(ERROR) << |
87 " FAILED to allocate GL context with LOSE_CONTEXT_ON_RESET_ARB"; | 93 " FAILED to allocate GL context with LOSE_CONTEXT_ON_RESET_ARB"; |
88 } | 94 } |
89 } | 95 } |
90 | 96 |
| 97 CHECK_X_ERROR(); |
| 98 |
91 if (!context_) { | 99 if (!context_) { |
92 // The means by which the context is created depends on whether | 100 // The means by which the context is created depends on whether |
93 // the drawable type works reliably with GLX 1.3. If it does not | 101 // the drawable type works reliably with GLX 1.3. If it does not |
94 // then fall back to GLX 1.2. | 102 // then fall back to GLX 1.2. |
95 if (surface_glx->IsOffscreen()) { | 103 if (surface_glx->IsOffscreen()) { |
96 context_ = glXCreateNewContext( | 104 context_ = glXCreateNewContext( |
97 GLSurfaceGLX::GetDisplay(), | 105 GLSurfaceGLX::GetDisplay(), |
98 static_cast<GLXFBConfig>(surface_glx->GetConfig()), | 106 static_cast<GLXFBConfig>(surface_glx->GetConfig()), |
99 GLX_RGBA_TYPE, | 107 GLX_RGBA_TYPE, |
100 share_handle, | 108 share_handle, |
101 True); | 109 True); |
102 } else { | 110 } else { |
103 Display* display = GLSurfaceGLX::GetDisplay(); | 111 Display* display = GLSurfaceGLX::GetDisplay(); |
104 | 112 |
105 // Get the visuals for the X drawable. | 113 // Get the visuals for the X drawable. |
106 XWindowAttributes attributes; | 114 XWindowAttributes attributes; |
107 if (!XGetWindowAttributes( | 115 if (!XGetWindowAttributes( |
108 display, | 116 display, |
109 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()), | 117 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()), |
110 &attributes)) { | 118 &attributes)) { |
111 LOG(ERROR) << "XGetWindowAttributes failed for window " << | 119 LOG(ERROR) << "XGetWindowAttributes failed for window " << |
112 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()) << "."; | 120 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()) << "."; |
113 return false; | 121 return false; |
114 } | 122 } |
115 | 123 |
| 124 CHECK_X_ERROR(); |
| 125 |
116 XVisualInfo visual_info_template; | 126 XVisualInfo visual_info_template; |
117 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); | 127 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); |
118 | 128 |
119 int visual_info_count = 0; | 129 int visual_info_count = 0; |
120 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info_list( | 130 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info_list( |
121 XGetVisualInfo(display, VisualIDMask, | 131 XGetVisualInfo(display, VisualIDMask, |
122 &visual_info_template, | 132 &visual_info_template, |
123 &visual_info_count)); | 133 &visual_info_count)); |
124 | 134 |
125 DCHECK(visual_info_list.get()); | 135 DCHECK(visual_info_list.get()); |
126 if (visual_info_count == 0) { | 136 if (visual_info_count == 0) { |
127 LOG(ERROR) << "No visual info for visual ID."; | 137 LOG(ERROR) << "No visual info for visual ID."; |
128 return false; | 138 return false; |
129 } | 139 } |
130 | 140 |
131 // Attempt to create a context with each visual in turn until one works. | 141 // Attempt to create a context with each visual in turn until one works. |
132 context_ = glXCreateContext( | 142 context_ = glXCreateContext( |
133 display, | 143 display, |
134 visual_info_list.get(), | 144 visual_info_list.get(), |
135 share_handle, | 145 share_handle, |
136 True); | 146 True); |
137 } | 147 } |
138 } | 148 } |
| 149 CHECK_X_ERROR(); |
139 | 150 |
140 if (!context_) { | 151 if (!context_) { |
141 LOG(ERROR) << "Couldn't create GL context."; | 152 LOG(ERROR) << "Couldn't create GL context."; |
142 Destroy(); | 153 Destroy(); |
143 return false; | 154 return false; |
144 } | 155 } |
145 | 156 |
146 DLOG(INFO) << (surface_glx->IsOffscreen() ? "Offscreen" : "Onscreen") | 157 DLOG(INFO) << (surface_glx->IsOffscreen() ? "Offscreen" : "Onscreen") |
147 << " context was " | 158 << " context was " |
148 << (glXIsDirect(GLSurfaceGLX::GetDisplay(), | 159 << (glXIsDirect(GLSurfaceGLX::GetDisplay(), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 255 } |
245 | 256 |
246 return GLContext::GetExtensions(); | 257 return GLContext::GetExtensions(); |
247 } | 258 } |
248 | 259 |
249 bool GLContextGLX::WasAllocatedUsingARBRobustness() { | 260 bool GLContextGLX::WasAllocatedUsingARBRobustness() { |
250 return GLSurfaceGLX::IsCreateContextRobustnessSupported(); | 261 return GLSurfaceGLX::IsCreateContextRobustnessSupported(); |
251 } | 262 } |
252 | 263 |
253 } // namespace gfx | 264 } // namespace gfx |
OLD | NEW |