| 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 13 matching lines...) Expand all Loading... |
| 24 // scoped_ptr functor for XFree(). Use as follows: | 24 // scoped_ptr functor for XFree(). Use as follows: |
| 25 // scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> foo(...); | 25 // scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> foo(...); |
| 26 // where "XVisualInfo" is any X type that is freed with XFree. | 26 // where "XVisualInfo" is any X type that is freed with XFree. |
| 27 class ScopedPtrXFree { | 27 class ScopedPtrXFree { |
| 28 public: | 28 public: |
| 29 void operator()(void* x) const { | 29 void operator()(void* x) const { |
| 30 ::XFree(x); | 30 ::XFree(x); |
| 31 } | 31 } |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 Display* g_display; | |
| 35 const char* g_glx_extensions = NULL; | 34 const char* g_glx_extensions = NULL; |
| 36 bool g_glx_create_context_robustness_supported = false; | 35 bool g_glx_create_context_robustness_supported = false; |
| 37 | 36 |
| 38 } // namespace anonymous | 37 } // namespace anonymous |
| 39 | 38 |
| 40 GLSurfaceGLX::GLSurfaceGLX() { | 39 GLSurfaceGLX::GLSurfaceGLX() { |
| 41 } | 40 } |
| 42 | 41 |
| 43 GLSurfaceGLX::~GLSurfaceGLX() { | 42 GLSurfaceGLX::~GLSurfaceGLX() { |
| 44 } | 43 } |
| 45 | 44 |
| 46 bool GLSurfaceGLX::InitializeOneOff() { | 45 bool GLSurfaceGLX::InitializeOneOff() { |
| 47 static bool initialized = false; | 46 static bool initialized = false; |
| 48 if (initialized) | 47 if (initialized) |
| 49 return true; | 48 return true; |
| 50 | 49 |
| 51 g_display = XOpenDisplay(NULL); | 50 if (!ui::GetXDisplay()) { |
| 52 if (!g_display) { | |
| 53 LOG(ERROR) << "XOpenDisplay failed."; | 51 LOG(ERROR) << "XOpenDisplay failed."; |
| 54 return false; | 52 return false; |
| 55 } | 53 } |
| 56 | 54 |
| 57 int major, minor; | 55 int major, minor; |
| 58 if (!glXQueryVersion(g_display, &major, &minor)) { | 56 if (!glXQueryVersion(ui::GetXDisplay(), &major, &minor)) { |
| 59 LOG(ERROR) << "glxQueryVersion failed"; | 57 LOG(ERROR) << "glxQueryVersion failed"; |
| 60 return false; | 58 return false; |
| 61 } | 59 } |
| 62 | 60 |
| 63 if (major == 1 && minor < 3) { | 61 if (major == 1 && minor < 3) { |
| 64 LOG(ERROR) << "GLX 1.3 or later is required."; | 62 LOG(ERROR) << "GLX 1.3 or later is required."; |
| 65 return false; | 63 return false; |
| 66 } | 64 } |
| 67 | 65 |
| 68 g_glx_extensions = glXQueryExtensionsString(g_display, 0); | 66 g_glx_extensions = glXQueryExtensionsString(ui::GetXDisplay(), 0); |
| 69 g_glx_create_context_robustness_supported = | 67 g_glx_create_context_robustness_supported = |
| 70 HasGLXExtension("GLX_ARB_create_context_robustness"); | 68 HasGLXExtension("GLX_ARB_create_context_robustness"); |
| 71 | 69 |
| 72 initialized = true; | 70 initialized = true; |
| 73 return true; | 71 return true; |
| 74 } | 72 } |
| 75 | 73 |
| 76 // static | 74 // static |
| 77 const char* GLSurfaceGLX::GetGLXExtensions() { | 75 const char* GLSurfaceGLX::GetGLXExtensions() { |
| 78 return g_glx_extensions; | 76 return g_glx_extensions; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 | 90 |
| 93 return extensions.find(delimited_name) != std::string::npos; | 91 return extensions.find(delimited_name) != std::string::npos; |
| 94 } | 92 } |
| 95 | 93 |
| 96 // static | 94 // static |
| 97 bool GLSurfaceGLX::IsCreateContextRobustnessSupported() { | 95 bool GLSurfaceGLX::IsCreateContextRobustnessSupported() { |
| 98 return g_glx_create_context_robustness_supported; | 96 return g_glx_create_context_robustness_supported; |
| 99 } | 97 } |
| 100 | 98 |
| 101 void* GLSurfaceGLX::GetDisplay() { | 99 void* GLSurfaceGLX::GetDisplay() { |
| 102 return g_display; | 100 return ui::GetXDisplay(); |
| 103 } | 101 } |
| 104 | 102 |
| 105 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::PluginWindowHandle window) | 103 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::PluginWindowHandle window) |
| 106 : window_(window), | 104 : window_(window), |
| 107 config_(NULL) { | 105 config_(NULL) { |
| 108 } | 106 } |
| 109 | 107 |
| 110 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() | 108 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() |
| 111 : window_(0), | 109 : window_(0), |
| 112 config_(NULL) { | 110 config_(NULL) { |
| 113 } | 111 } |
| 114 | 112 |
| 115 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { | 113 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { |
| 116 Destroy(); | 114 Destroy(); |
| 117 } | 115 } |
| 118 | 116 |
| 119 bool NativeViewGLSurfaceGLX::Initialize() { | 117 bool NativeViewGLSurfaceGLX::Initialize() { |
| 120 return true; | 118 return true; |
| 121 } | 119 } |
| 122 | 120 |
| 123 void NativeViewGLSurfaceGLX::Destroy() { | 121 void NativeViewGLSurfaceGLX::Destroy() { |
| 124 } | 122 } |
| 125 | 123 |
| 126 bool NativeViewGLSurfaceGLX::IsOffscreen() { | 124 bool NativeViewGLSurfaceGLX::IsOffscreen() { |
| 127 return false; | 125 return false; |
| 128 } | 126 } |
| 129 | 127 |
| 130 bool NativeViewGLSurfaceGLX::SwapBuffers() { | 128 bool NativeViewGLSurfaceGLX::SwapBuffers() { |
| 131 glXSwapBuffers(g_display, window_); | 129 glXSwapBuffers(ui::GetXDisplay(), window_); |
| 132 return true; | 130 return true; |
| 133 } | 131 } |
| 134 | 132 |
| 135 gfx::Size NativeViewGLSurfaceGLX::GetSize() { | 133 gfx::Size NativeViewGLSurfaceGLX::GetSize() { |
| 136 XWindowAttributes attributes; | 134 XWindowAttributes attributes; |
| 137 if (!XGetWindowAttributes(g_display, window_, &attributes)) { | 135 if (!XGetWindowAttributes(ui::GetXDisplay(), window_, &attributes)) { |
| 138 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 136 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
| 139 return gfx::Size(); | 137 return gfx::Size(); |
| 140 } | 138 } |
| 141 return gfx::Size(attributes.width, attributes.height); | 139 return gfx::Size(attributes.width, attributes.height); |
| 142 } | 140 } |
| 143 | 141 |
| 144 void* NativeViewGLSurfaceGLX::GetHandle() { | 142 void* NativeViewGLSurfaceGLX::GetHandle() { |
| 145 return reinterpret_cast<void*>(window_); | 143 return reinterpret_cast<void*>(window_); |
| 146 } | 144 } |
| 147 | 145 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 163 // | 161 // |
| 164 // TODO(kbr): this is not a reliable code path. On platforms which | 162 // TODO(kbr): this is not a reliable code path. On platforms which |
| 165 // support it, we should use glXChooseFBConfig in the browser | 163 // support it, we should use glXChooseFBConfig in the browser |
| 166 // process to choose the FBConfig and from there the X Visual to | 164 // process to choose the FBConfig and from there the X Visual to |
| 167 // use when creating the window in the first place. Then we can | 165 // use when creating the window in the first place. Then we can |
| 168 // pass that FBConfig down rather than attempting to reconstitute | 166 // pass that FBConfig down rather than attempting to reconstitute |
| 169 // it. | 167 // it. |
| 170 | 168 |
| 171 XWindowAttributes attributes; | 169 XWindowAttributes attributes; |
| 172 if (!XGetWindowAttributes( | 170 if (!XGetWindowAttributes( |
| 173 g_display, | 171 ui::GetXDisplay(), |
| 174 reinterpret_cast<GLXDrawable>(GetHandle()), | 172 reinterpret_cast<GLXDrawable>(GetHandle()), |
| 175 &attributes)) { | 173 &attributes)) { |
| 176 LOG(ERROR) << "XGetWindowAttributes failed for window " << | 174 LOG(ERROR) << "XGetWindowAttributes failed for window " << |
| 177 reinterpret_cast<GLXDrawable>(GetHandle()) << "."; | 175 reinterpret_cast<GLXDrawable>(GetHandle()) << "."; |
| 178 return NULL; | 176 return NULL; |
| 179 } | 177 } |
| 180 | 178 |
| 181 int visual_id = XVisualIDFromVisual(attributes.visual); | 179 int visual_id = XVisualIDFromVisual(attributes.visual); |
| 182 | 180 |
| 183 int num_elements = 0; | 181 int num_elements = 0; |
| 184 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> configs( | 182 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> configs( |
| 185 glXGetFBConfigs(g_display, | 183 glXGetFBConfigs(ui::GetXDisplay(), |
| 186 DefaultScreen(g_display), | 184 DefaultScreen(ui::GetXDisplay()), |
| 187 &num_elements)); | 185 &num_elements)); |
| 188 if (!configs.get()) { | 186 if (!configs.get()) { |
| 189 LOG(ERROR) << "glXGetFBConfigs failed."; | 187 LOG(ERROR) << "glXGetFBConfigs failed."; |
| 190 return NULL; | 188 return NULL; |
| 191 } | 189 } |
| 192 if (!num_elements) { | 190 if (!num_elements) { |
| 193 LOG(ERROR) << "glXGetFBConfigs returned 0 elements."; | 191 LOG(ERROR) << "glXGetFBConfigs returned 0 elements."; |
| 194 return NULL; | 192 return NULL; |
| 195 } | 193 } |
| 196 bool found = false; | 194 bool found = false; |
| 197 int i; | 195 int i; |
| 198 for (i = 0; i < num_elements; ++i) { | 196 for (i = 0; i < num_elements; ++i) { |
| 199 int value; | 197 int value; |
| 200 if (glXGetFBConfigAttrib( | 198 if (glXGetFBConfigAttrib( |
| 201 g_display, configs.get()[i], GLX_VISUAL_ID, &value)) { | 199 ui::GetXDisplay(), configs.get()[i], GLX_VISUAL_ID, &value)) { |
| 202 LOG(ERROR) << "glXGetFBConfigAttrib failed."; | 200 LOG(ERROR) << "glXGetFBConfigAttrib failed."; |
| 203 return NULL; | 201 return NULL; |
| 204 } | 202 } |
| 205 if (value == visual_id) { | 203 if (value == visual_id) { |
| 206 found = true; | 204 found = true; |
| 207 break; | 205 break; |
| 208 } | 206 } |
| 209 } | 207 } |
| 210 if (found) { | 208 if (found) { |
| 211 config_ = configs.get()[i]; | 209 config_ = configs.get()[i]; |
| 212 } | 210 } |
| 213 } | 211 } |
| 214 | 212 |
| 215 return config_; | 213 return config_; |
| 216 } | 214 } |
| 217 | 215 |
| 218 bool NativeViewGLSurfaceGLX::PostSubBuffer( | 216 bool NativeViewGLSurfaceGLX::PostSubBuffer( |
| 219 int x, int y, int width, int height) { | 217 int x, int y, int width, int height) { |
| 220 DCHECK(g_GLX_MESA_copy_sub_buffer); | 218 DCHECK(g_GLX_MESA_copy_sub_buffer); |
| 221 glXCopySubBufferMESA(g_display, window_, x, y, width, height); | 219 glXCopySubBufferMESA(ui::GetXDisplay(), window_, x, y, width, height); |
| 222 return true; | 220 return true; |
| 223 } | 221 } |
| 224 | 222 |
| 225 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) | 223 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) |
| 226 : size_(size), | 224 : size_(size), |
| 227 config_(NULL), | 225 config_(NULL), |
| 228 pbuffer_(0) { | 226 pbuffer_(0) { |
| 229 } | 227 } |
| 230 | 228 |
| 231 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 229 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 242 GLX_GREEN_SIZE, 8, | 240 GLX_GREEN_SIZE, 8, |
| 243 GLX_RED_SIZE, 8, | 241 GLX_RED_SIZE, 8, |
| 244 GLX_RENDER_TYPE, GLX_RGBA_BIT, | 242 GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 245 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, | 243 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, |
| 246 GLX_DOUBLEBUFFER, False, | 244 GLX_DOUBLEBUFFER, False, |
| 247 0 | 245 0 |
| 248 }; | 246 }; |
| 249 | 247 |
| 250 int num_elements = 0; | 248 int num_elements = 0; |
| 251 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> configs( | 249 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> configs( |
| 252 glXChooseFBConfig(g_display, | 250 glXChooseFBConfig(ui::GetXDisplay(), |
| 253 DefaultScreen(g_display), | 251 DefaultScreen(ui::GetXDisplay()), |
| 254 config_attributes, | 252 config_attributes, |
| 255 &num_elements)); | 253 &num_elements)); |
| 256 if (!configs.get()) { | 254 if (!configs.get()) { |
| 257 LOG(ERROR) << "glXChooseFBConfig failed."; | 255 LOG(ERROR) << "glXChooseFBConfig failed."; |
| 258 return false; | 256 return false; |
| 259 } | 257 } |
| 260 if (!num_elements) { | 258 if (!num_elements) { |
| 261 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; | 259 LOG(ERROR) << "glXChooseFBConfig returned 0 elements."; |
| 262 return false; | 260 return false; |
| 263 } | 261 } |
| 264 | 262 |
| 265 config_ = configs.get()[0]; | 263 config_ = configs.get()[0]; |
| 266 | 264 |
| 267 const int pbuffer_attributes[] = { | 265 const int pbuffer_attributes[] = { |
| 268 GLX_PBUFFER_WIDTH, size_.width(), | 266 GLX_PBUFFER_WIDTH, size_.width(), |
| 269 GLX_PBUFFER_HEIGHT, size_.height(), | 267 GLX_PBUFFER_HEIGHT, size_.height(), |
| 270 0 | 268 0 |
| 271 }; | 269 }; |
| 272 pbuffer_ = glXCreatePbuffer(g_display, | 270 pbuffer_ = glXCreatePbuffer(ui::GetXDisplay(), |
| 273 static_cast<GLXFBConfig>(config_), | 271 static_cast<GLXFBConfig>(config_), |
| 274 pbuffer_attributes); | 272 pbuffer_attributes); |
| 275 if (!pbuffer_) { | 273 if (!pbuffer_) { |
| 276 Destroy(); | 274 Destroy(); |
| 277 LOG(ERROR) << "glXCreatePbuffer failed."; | 275 LOG(ERROR) << "glXCreatePbuffer failed."; |
| 278 return false; | 276 return false; |
| 279 } | 277 } |
| 280 | 278 |
| 281 return true; | 279 return true; |
| 282 } | 280 } |
| 283 | 281 |
| 284 void PbufferGLSurfaceGLX::Destroy() { | 282 void PbufferGLSurfaceGLX::Destroy() { |
| 285 if (pbuffer_) { | 283 if (pbuffer_) { |
| 286 glXDestroyPbuffer(g_display, pbuffer_); | 284 glXDestroyPbuffer(ui::GetXDisplay(), pbuffer_); |
| 287 pbuffer_ = 0; | 285 pbuffer_ = 0; |
| 288 } | 286 } |
| 289 | 287 |
| 290 config_ = NULL; | 288 config_ = NULL; |
| 291 } | 289 } |
| 292 | 290 |
| 293 bool PbufferGLSurfaceGLX::IsOffscreen() { | 291 bool PbufferGLSurfaceGLX::IsOffscreen() { |
| 294 return true; | 292 return true; |
| 295 } | 293 } |
| 296 | 294 |
| 297 bool PbufferGLSurfaceGLX::SwapBuffers() { | 295 bool PbufferGLSurfaceGLX::SwapBuffers() { |
| 298 NOTREACHED() << "Attempted to call SwapBuffers on a pbuffer."; | 296 NOTREACHED() << "Attempted to call SwapBuffers on a pbuffer."; |
| 299 return false; | 297 return false; |
| 300 } | 298 } |
| 301 | 299 |
| 302 gfx::Size PbufferGLSurfaceGLX::GetSize() { | 300 gfx::Size PbufferGLSurfaceGLX::GetSize() { |
| 303 return size_; | 301 return size_; |
| 304 } | 302 } |
| 305 | 303 |
| 306 void* PbufferGLSurfaceGLX::GetHandle() { | 304 void* PbufferGLSurfaceGLX::GetHandle() { |
| 307 return reinterpret_cast<void*>(pbuffer_); | 305 return reinterpret_cast<void*>(pbuffer_); |
| 308 } | 306 } |
| 309 | 307 |
| 310 void* PbufferGLSurfaceGLX::GetConfig() { | 308 void* PbufferGLSurfaceGLX::GetConfig() { |
| 311 return config_; | 309 return config_; |
| 312 } | 310 } |
| 313 | 311 |
| 314 } // namespace gfx | 312 } // namespace gfx |
| OLD | NEW |