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 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 net_wm_cm_s0 = XInternAtom(display, "_NET_WM_CM_S0", True); | 26 net_wm_cm_s0 = XInternAtom(display, "_NET_WM_CM_S0", True); |
| 27 } | 27 } |
| 28 if (net_wm_cm_s0 == kNone) { | 28 if (net_wm_cm_s0 == kNone) { |
| 29 return false; | 29 return false; |
| 30 } | 30 } |
| 31 return XGetSelectionOwner(display, net_wm_cm_s0) != kNone; | 31 return XGetSelectionOwner(display, net_wm_cm_s0) != kNone; |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace anonymous | 34 } // namespace anonymous |
| 35 | 35 |
| 36 GLContextGLX::GLContextGLX(GLSurfaceGLX* surface) | 36 GLContextGLX::GLContextGLX() |
| 37 : surface_(surface), | 37 : context_(NULL) { |
| 38 context_(NULL) { | |
| 39 } | 38 } |
| 40 | 39 |
| 41 GLContextGLX::~GLContextGLX() { | 40 GLContextGLX::~GLContextGLX() { |
| 42 Destroy(); | 41 Destroy(); |
| 43 } | 42 } |
| 44 | 43 |
| 45 bool GLContextGLX::Initialize(GLContext* shared_context) { | 44 bool GLContextGLX::Initialize(GLContext* shared_context) { |
| 46 context_ = glXCreateNewContext( | 45 context_ = glXCreateNewContext( |
| 47 GLSurfaceGLX::GetDisplay(), | 46 GLSurfaceGLX::GetDisplay(), |
| 48 static_cast<GLXFBConfig>(surface_->GetConfig()), | 47 static_cast<GLXFBConfig>(NULL /* TODO: fix */), |
|
Alexey Marinichev
2011/05/17 20:20:54
Nvidia driver segfaults on this. No good!
| |
| 49 GLX_RGBA_TYPE, | 48 GLX_RGBA_TYPE, |
| 50 static_cast<GLXContext>( | 49 static_cast<GLXContext>( |
| 51 shared_context ? shared_context->GetHandle() : NULL), | 50 shared_context ? shared_context->GetHandle() : NULL), |
| 52 True); | 51 True); |
| 53 if (!context_) { | 52 if (!context_) { |
| 54 LOG(ERROR) << "Couldn't create GL context."; | 53 LOG(ERROR) << "Couldn't create GL context."; |
| 55 Destroy(); | 54 Destroy(); |
| 56 return false; | 55 return false; |
| 57 } | 56 } |
| 58 | 57 |
| 59 return true; | 58 return true; |
| 60 } | 59 } |
| 61 | 60 |
| 62 void GLContextGLX::Destroy() { | 61 void GLContextGLX::Destroy() { |
| 63 if (context_) { | 62 if (context_) { |
| 64 glXDestroyContext(GLSurfaceGLX::GetDisplay(), | 63 glXDestroyContext(GLSurfaceGLX::GetDisplay(), |
| 65 static_cast<GLXContext>(context_)); | 64 static_cast<GLXContext>(context_)); |
| 66 context_ = NULL; | 65 context_ = NULL; |
| 67 } | 66 } |
| 68 } | 67 } |
| 69 | 68 |
| 70 bool GLContextGLX::MakeCurrent() { | 69 bool GLContextGLX::MakeCurrent(GLSurface* surface) { |
| 71 if (IsCurrent()) { | 70 DCHECK(context_); |
| 71 if (IsCurrent(surface)) | |
| 72 return true; | 72 return true; |
| 73 } | |
| 74 | 73 |
| 75 if (!glXMakeContextCurrent( | 74 if (!glXMakeContextCurrent( |
| 76 GLSurfaceGLX::GetDisplay(), | 75 GLSurfaceGLX::GetDisplay(), |
| 77 reinterpret_cast<GLXDrawable>(surface_->GetHandle()), | 76 reinterpret_cast<GLXDrawable>(surface->GetHandle()), |
| 78 reinterpret_cast<GLXDrawable>(surface_->GetHandle()), | 77 reinterpret_cast<GLXDrawable>(surface->GetHandle()), |
| 79 static_cast<GLXContext>(context_))) { | 78 static_cast<GLXContext>(context_))) { |
| 80 Destroy(); | 79 Destroy(); |
| 81 LOG(ERROR) << "Couldn't make context current."; | 80 LOG(ERROR) << "Couldn't make context current."; |
| 82 return false; | 81 return false; |
| 83 } | 82 } |
| 84 | 83 |
| 85 return true; | 84 return true; |
| 86 } | 85 } |
| 87 | 86 |
| 88 bool GLContextGLX::IsCurrent() { | 87 void GLContextGLX::ReleaseCurrent(GLSurface* surface) { |
| 89 // TODO(apatrick): When surface is split from context, cannot use surface_ | 88 if (!IsCurrent(surface)) |
| 90 // here. | 89 return; |
| 91 return glXGetCurrentDrawable() == | 90 |
| 92 reinterpret_cast<GLXDrawable>(surface_->GetHandle()) && | 91 glXMakeContextCurrent(GLSurfaceGLX::GetDisplay(), 0, 0, NULL); |
| 93 glXGetCurrentContext() == static_cast<GLXContext>(context_); | |
| 94 } | 92 } |
| 95 | 93 |
| 96 bool GLContextGLX::IsOffscreen() { | 94 bool GLContextGLX::IsCurrent(GLSurface* surface) { |
| 97 // TODO(apatrick): remove this from GLContext interface. | 95 if (glXGetCurrentContext() == static_cast<GLXContext>(context_)) |
| 98 return surface_->IsOffscreen(); | 96 return false; |
| 99 } | |
| 100 | 97 |
| 101 bool GLContextGLX::SwapBuffers() { | 98 if (surface) { |
| 102 // TODO(apatrick): remove this from GLContext interface. | 99 if (glXGetCurrentDrawable() != |
| 103 return surface_->SwapBuffers(); | 100 reinterpret_cast<GLXDrawable>(surface->GetHandle())) { |
| 104 } | 101 return false; |
| 102 } | |
| 103 } | |
| 105 | 104 |
| 106 gfx::Size GLContextGLX::GetSize() { | 105 return true; |
| 107 // TODO(apatrick): remove this from GLContext interface. | |
| 108 return surface_->GetSize(); | |
| 109 } | 106 } |
| 110 | 107 |
| 111 void* GLContextGLX::GetHandle() { | 108 void* GLContextGLX::GetHandle() { |
| 112 return context_; | 109 return context_; |
| 113 } | 110 } |
| 114 | 111 |
| 115 void GLContextGLX::SetSwapInterval(int interval) { | 112 void GLContextGLX::SetSwapInterval(int interval) { |
| 116 DCHECK(IsCurrent()); | 113 DCHECK(IsCurrent(NULL)); |
| 117 if (HasExtension("GLX_EXT_swap_control") && glXSwapIntervalEXT) { | 114 if (HasExtension("GLX_EXT_swap_control") && glXSwapIntervalEXT) { |
| 118 // Only enable vsync if we aren't using a compositing window | 115 // Only enable vsync if we aren't using a compositing window |
| 119 // manager. At the moment, compositing window managers don't | 116 // manager. At the moment, compositing window managers don't |
| 120 // respect this setting anyway (tearing still occurs) and it | 117 // respect this setting anyway (tearing still occurs) and it |
| 121 // dramatically increases latency. | 118 // dramatically increases latency. |
| 122 if (!IsCompositingWindowManagerActive(GLSurfaceGLX::GetDisplay())) { | 119 if (!IsCompositingWindowManagerActive(GLSurfaceGLX::GetDisplay())) { |
| 123 glXSwapIntervalEXT( | 120 glXSwapIntervalEXT( |
| 124 GLSurfaceGLX::GetDisplay(), | 121 GLSurfaceGLX::GetDisplay(), |
| 125 reinterpret_cast<GLXDrawable>(surface_->GetHandle()), | 122 glXGetCurrentDrawable(), |
| 126 interval); | 123 interval); |
| 127 } | 124 } |
| 128 } | 125 } |
| 129 } | 126 } |
| 130 | 127 |
| 131 std::string GLContextGLX::GetExtensions() { | 128 std::string GLContextGLX::GetExtensions() { |
| 132 DCHECK(IsCurrent()); | 129 DCHECK(IsCurrent(NULL)); |
| 133 const char* extensions = glXQueryExtensionsString( | 130 const char* extensions = glXQueryExtensionsString( |
| 134 GLSurfaceGLX::GetDisplay(), | 131 GLSurfaceGLX::GetDisplay(), |
| 135 0); | 132 0); |
| 136 if (extensions) { | 133 if (extensions) { |
| 137 return GLContext::GetExtensions() + " " + extensions; | 134 return GLContext::GetExtensions() + " " + extensions; |
| 138 } | 135 } |
| 139 | 136 |
| 140 return GLContext::GetExtensions(); | 137 return GLContext::GetExtensions(); |
| 141 } | 138 } |
| 142 | 139 |
| 143 } // namespace gfx | 140 } // namespace gfx |
| OLD | NEW |