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