| 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_surface_glx.h" | 9 #include "ui/gfx/gl/gl_surface_glx.h" |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 g_glx_extensions = glXQueryExtensionsString(g_display, 0); | 68 g_glx_extensions = glXQueryExtensionsString(g_display, 0); |
| 69 g_glx_create_context_robustness_supported = | 69 g_glx_create_context_robustness_supported = |
| 70 HasGLXExtension("GLX_ARB_create_context_robustness"); | 70 HasGLXExtension("GLX_ARB_create_context_robustness"); |
| 71 | 71 |
| 72 initialized = true; | 72 initialized = true; |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // static |
| 76 const char* GLSurfaceGLX::GetGLXExtensions() { | 77 const char* GLSurfaceGLX::GetGLXExtensions() { |
| 77 return g_glx_extensions; | 78 return g_glx_extensions; |
| 78 } | 79 } |
| 79 | 80 |
| 81 // static |
| 80 bool GLSurfaceGLX::HasGLXExtension(const char* name) { | 82 bool GLSurfaceGLX::HasGLXExtension(const char* name) { |
| 81 DCHECK(name); | 83 DCHECK(name); |
| 82 const char* c_extensions = GetGLXExtensions(); | 84 const char* c_extensions = GetGLXExtensions(); |
| 83 if (!c_extensions) | 85 if (!c_extensions) |
| 84 return false; | 86 return false; |
| 85 std::string extensions(c_extensions); | 87 std::string extensions(c_extensions); |
| 86 extensions += " "; | 88 extensions += " "; |
| 87 | 89 |
| 88 std::string delimited_name(name); | 90 std::string delimited_name(name); |
| 89 delimited_name += " "; | 91 delimited_name += " "; |
| 90 | 92 |
| 91 return extensions.find(delimited_name) != std::string::npos; | 93 return extensions.find(delimited_name) != std::string::npos; |
| 92 } | 94 } |
| 93 | 95 |
| 96 // static |
| 94 bool GLSurfaceGLX::IsCreateContextRobustnessSupported() { | 97 bool GLSurfaceGLX::IsCreateContextRobustnessSupported() { |
| 95 return g_glx_create_context_robustness_supported; | 98 return g_glx_create_context_robustness_supported; |
| 96 } | 99 } |
| 97 | 100 |
| 98 void* GLSurfaceGLX::GetDisplay() { | 101 void* GLSurfaceGLX::GetDisplay() { |
| 99 return g_display; | 102 return g_display; |
| 100 } | 103 } |
| 101 | 104 |
| 102 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::PluginWindowHandle window) | 105 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::PluginWindowHandle window) |
| 103 : window_(window), | 106 : window_(window), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 138 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
| 136 return gfx::Size(); | 139 return gfx::Size(); |
| 137 } | 140 } |
| 138 return gfx::Size(attributes.width, attributes.height); | 141 return gfx::Size(attributes.width, attributes.height); |
| 139 } | 142 } |
| 140 | 143 |
| 141 void* NativeViewGLSurfaceGLX::GetHandle() { | 144 void* NativeViewGLSurfaceGLX::GetHandle() { |
| 142 return reinterpret_cast<void*>(window_); | 145 return reinterpret_cast<void*>(window_); |
| 143 } | 146 } |
| 144 | 147 |
| 148 std::string NativeViewGLSurfaceGLX::GetExtensions() { |
| 149 std::string extensions = GLSurface::GetExtensions(); |
| 150 if (g_GLX_MESA_copy_sub_buffer) { |
| 151 extensions += extensions.empty() ? "" : " "; |
| 152 extensions += "GL_CHROMIUM_post_sub_buffer"; |
| 153 } |
| 154 return extensions; |
| 155 } |
| 156 |
| 145 void* NativeViewGLSurfaceGLX::GetConfig() { | 157 void* NativeViewGLSurfaceGLX::GetConfig() { |
| 146 if (!config_) { | 158 if (!config_) { |
| 147 // This code path is expensive, but we only take it when | 159 // This code path is expensive, but we only take it when |
| 148 // attempting to use GLX_ARB_create_context_robustness, in which | 160 // attempting to use GLX_ARB_create_context_robustness, in which |
| 149 // case we need a GLXFBConfig for the window in order to create a | 161 // case we need a GLXFBConfig for the window in order to create a |
| 150 // context for it. | 162 // context for it. |
| 151 // | 163 // |
| 152 // TODO(kbr): this is not a reliable code path. On platforms which | 164 // TODO(kbr): this is not a reliable code path. On platforms which |
| 153 // support it, we should use glXChooseFBConfig in the browser | 165 // support it, we should use glXChooseFBConfig in the browser |
| 154 // process to choose the FBConfig and from there the X Visual to | 166 // process to choose the FBConfig and from there the X Visual to |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 208 } |
| 197 } | 209 } |
| 198 if (found) { | 210 if (found) { |
| 199 config_ = configs.get()[i]; | 211 config_ = configs.get()[i]; |
| 200 } | 212 } |
| 201 } | 213 } |
| 202 | 214 |
| 203 return config_; | 215 return config_; |
| 204 } | 216 } |
| 205 | 217 |
| 206 bool NativeViewGLSurfaceGLX::SupportsPostSubBuffer() { | |
| 207 return g_GLX_MESA_copy_sub_buffer; | |
| 208 } | |
| 209 | |
| 210 bool NativeViewGLSurfaceGLX::PostSubBuffer( | 218 bool NativeViewGLSurfaceGLX::PostSubBuffer( |
| 211 int x, int y, int width, int height) { | 219 int x, int y, int width, int height) { |
| 212 DCHECK(SupportsPostSubBuffer()); | 220 DCHECK(g_GLX_MESA_copy_sub_buffer); |
| 213 glXCopySubBufferMESA(g_display, window_, x, y, width, height); | 221 glXCopySubBufferMESA(g_display, window_, x, y, width, height); |
| 214 return true; | 222 return true; |
| 215 } | 223 } |
| 216 | 224 |
| 217 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) | 225 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) |
| 218 : size_(size), | 226 : size_(size), |
| 219 config_(NULL), | 227 config_(NULL), |
| 220 pbuffer_(0) { | 228 pbuffer_(0) { |
| 221 } | 229 } |
| 222 | 230 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 305 |
| 298 void* PbufferGLSurfaceGLX::GetHandle() { | 306 void* PbufferGLSurfaceGLX::GetHandle() { |
| 299 return reinterpret_cast<void*>(pbuffer_); | 307 return reinterpret_cast<void*>(pbuffer_); |
| 300 } | 308 } |
| 301 | 309 |
| 302 void* PbufferGLSurfaceGLX::GetConfig() { | 310 void* PbufferGLSurfaceGLX::GetConfig() { |
| 303 return config_; | 311 return config_; |
| 304 } | 312 } |
| 305 | 313 |
| 306 } // namespace gfx | 314 } // namespace gfx |
| OLD | NEW |