Chromium Code Reviews| 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 |
| 18 namespace gfx { | 20 namespace gfx { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 // scoped_ptr functor for XFree(). Use as follows: | 24 // scoped_ptr functor for XFree(). Use as follows: |
| 23 // scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> foo(...); | 25 // scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> foo(...); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 35 static Atom net_wm_cm_s0 = kNone; | 37 static Atom net_wm_cm_s0 = kNone; |
| 36 if (net_wm_cm_s0 == static_cast<Atom>(kNone)) { | 38 if (net_wm_cm_s0 == static_cast<Atom>(kNone)) { |
| 37 net_wm_cm_s0 = XInternAtom(display, "_NET_WM_CM_S0", True); | 39 net_wm_cm_s0 = XInternAtom(display, "_NET_WM_CM_S0", True); |
| 38 } | 40 } |
| 39 if (net_wm_cm_s0 == static_cast<Atom>(kNone)) { | 41 if (net_wm_cm_s0 == static_cast<Atom>(kNone)) { |
| 40 return false; | 42 return false; |
| 41 } | 43 } |
| 42 return XGetSelectionOwner(display, net_wm_cm_s0) != static_cast<Atom>(kNone); | 44 return XGetSelectionOwner(display, net_wm_cm_s0) != static_cast<Atom>(kNone); |
| 43 } | 45 } |
| 44 | 46 |
| 47 bool g_has_x_error_ = false; | |
| 48 | |
| 49 int GLContextGLXErrorHandler(Display* d, XErrorEvent* e) { | |
| 50 g_has_x_error_ = true; | |
| 51 ui::LogErrorEventDescription(d, *e); | |
|
Ami GONE FROM CHROMIUM
2011/09/14 17:11:13
not legit per NOTE @ x11_util_internal.h:46.
dominich
2011/09/14 19:55:06
Done.
| |
| 52 return 0; | |
| 53 } | |
| 54 | |
| 45 } // namespace anonymous | 55 } // namespace anonymous |
| 46 | 56 |
| 47 GLContextGLX::GLContextGLX(GLShareGroup* share_group) | 57 GLContextGLX::GLContextGLX(GLShareGroup* share_group) |
| 48 : GLContext(share_group), | 58 : GLContext(share_group), |
| 49 context_(NULL) { | 59 context_(NULL) { |
| 50 } | 60 } |
| 51 | 61 |
| 52 GLContextGLX::~GLContextGLX() { | 62 GLContextGLX::~GLContextGLX() { |
| 53 Destroy(); | 63 Destroy(); |
| 54 } | 64 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 if (surface_glx->IsOffscreen()) { | 105 if (surface_glx->IsOffscreen()) { |
| 96 context_ = glXCreateNewContext( | 106 context_ = glXCreateNewContext( |
| 97 GLSurfaceGLX::GetDisplay(), | 107 GLSurfaceGLX::GetDisplay(), |
| 98 static_cast<GLXFBConfig>(surface_glx->GetConfig()), | 108 static_cast<GLXFBConfig>(surface_glx->GetConfig()), |
| 99 GLX_RGBA_TYPE, | 109 GLX_RGBA_TYPE, |
| 100 share_handle, | 110 share_handle, |
| 101 True); | 111 True); |
| 102 } else { | 112 } else { |
| 103 Display* display = GLSurfaceGLX::GetDisplay(); | 113 Display* display = GLSurfaceGLX::GetDisplay(); |
| 104 | 114 |
| 115 // We only need to override the non-fatal X error handler. | |
| 116 ui::ScopedX11ErrorHandlerOverride handler_override( | |
| 117 GLContextGLXErrorHandler, NULL); | |
| 118 | |
|
marcheu
2011/09/14 17:02:43
Why not do this earlier in the function? glX funct
dominich
2011/09/14 19:55:06
Done.
| |
| 105 // Get the visuals for the X drawable. | 119 // Get the visuals for the X drawable. |
| 106 XWindowAttributes attributes; | 120 XWindowAttributes attributes; |
| 107 if (!XGetWindowAttributes( | 121 if (!XGetWindowAttributes( |
| 108 display, | 122 display, |
| 109 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()), | 123 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()), |
| 110 &attributes)) { | 124 &attributes)) { |
| 111 LOG(ERROR) << "XGetWindowAttributes failed for window " << | 125 LOG(ERROR) << "XGetWindowAttributes failed for window " << |
| 112 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()) << "."; | 126 reinterpret_cast<GLXDrawable>(surface_glx->GetHandle()) << "."; |
| 113 return false; | 127 return false; |
| 114 } | 128 } |
| 115 | 129 |
| 130 // Allow any errors to be caught. | |
| 131 XSync(display, False); | |
| 132 CHECK(!g_has_x_error_); | |
|
Ami GONE FROM CHROMIUM
2011/09/14 17:11:13
If this is all you care about, why not make the de
dominich
2011/09/14 17:15:57
There are two sets of default handlers, one of whi
Ami GONE FROM CHROMIUM
2011/09/14 17:20:50
An alternative to depending on a specific handler
| |
| 133 | |
|
marcheu
2011/09/14 17:02:43
Why not do this later in the function? There are m
dominich
2011/09/14 19:55:06
Done.
| |
| 116 XVisualInfo visual_info_template; | 134 XVisualInfo visual_info_template; |
| 117 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); | 135 visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); |
| 118 | 136 |
| 119 int visual_info_count = 0; | 137 int visual_info_count = 0; |
| 120 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info_list( | 138 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info_list( |
| 121 XGetVisualInfo(display, VisualIDMask, | 139 XGetVisualInfo(display, VisualIDMask, |
| 122 &visual_info_template, | 140 &visual_info_template, |
| 123 &visual_info_count)); | 141 &visual_info_count)); |
| 124 | 142 |
| 125 DCHECK(visual_info_list.get()); | 143 DCHECK(visual_info_list.get()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 } | 262 } |
| 245 | 263 |
| 246 return GLContext::GetExtensions(); | 264 return GLContext::GetExtensions(); |
| 247 } | 265 } |
| 248 | 266 |
| 249 bool GLContextGLX::WasAllocatedUsingARBRobustness() { | 267 bool GLContextGLX::WasAllocatedUsingARBRobustness() { |
| 250 return GLSurfaceGLX::IsCreateContextRobustnessSupported(); | 268 return GLSurfaceGLX::IsCreateContextRobustnessSupported(); |
| 251 } | 269 } |
| 252 | 270 |
| 253 } // namespace gfx | 271 } // namespace gfx |
| OLD | NEW |