OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gl/gl_surface_glx.h" | 9 #include "ui/gl/gl_surface_glx.h" |
10 | 10 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 314 } |
315 | 315 |
316 void* PbufferGLSurfaceGLX::GetConfig() { | 316 void* PbufferGLSurfaceGLX::GetConfig() { |
317 return config_; | 317 return config_; |
318 } | 318 } |
319 | 319 |
320 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 320 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
321 Destroy(); | 321 Destroy(); |
322 } | 322 } |
323 | 323 |
| 324 PixmapGLSurfaceGLX::PixmapGLSurfaceGLX(XID pixmap) |
| 325 : config_(NULL), |
| 326 pixmap_(pixmap), |
| 327 glx_pixmap_(0) { |
| 328 } |
| 329 |
| 330 bool PixmapGLSurfaceGLX::Initialize() { |
| 331 DCHECK(pixmap_); |
| 332 |
| 333 XID root; |
| 334 int x, y; |
| 335 unsigned int width, height, border_width, depth; |
| 336 if (!XGetGeometry(g_display, pixmap_, &root, &x, &y, &width, &height, |
| 337 &border_width, &depth)) { |
| 338 LOG(ERROR) << "XGetGeometry failed for pixmap " << pixmap_ << "."; |
| 339 return false; |
| 340 } |
| 341 size_ = gfx::Size(width, height); |
| 342 |
| 343 int num_elements = 0; |
| 344 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> configs( |
| 345 glXGetFBConfigs(g_display, |
| 346 DefaultScreen(g_display), |
| 347 &num_elements)); |
| 348 if (!configs.get()) { |
| 349 LOG(ERROR) << "glXGetFBConfigs failed."; |
| 350 return false; |
| 351 } |
| 352 if (!num_elements) { |
| 353 LOG(ERROR) << "glXGetFBConfigs returned 0 elements."; |
| 354 return false; |
| 355 } |
| 356 bool found = false; |
| 357 int i; |
| 358 for (i = 0; i < num_elements; ++i) { |
| 359 int value; |
| 360 if (glXGetFBConfigAttrib( |
| 361 g_display, configs.get()[i], GLX_DRAWABLE_TYPE, &value)) { |
| 362 LOG(ERROR) << "glXGetFBConfigAttrib failed."; |
| 363 return false; |
| 364 } |
| 365 if (!(value & GLX_PIXMAP_BIT)) |
| 366 continue; |
| 367 if (glXGetFBConfigAttrib( |
| 368 g_display, configs.get()[i], GLX_BIND_TO_TEXTURE_TARGETS_EXT, |
| 369 &value)) { |
| 370 LOG(ERROR) << "glXGetFBConfigAttrib failed."; |
| 371 return false; |
| 372 } |
| 373 if (!(value & GLX_TEXTURE_2D_BIT_EXT)) |
| 374 continue; |
| 375 if (glXGetFBConfigAttrib( |
| 376 g_display, configs.get()[i], (depth == 32) ? |
| 377 GLX_BIND_TO_TEXTURE_RGBA_EXT : GLX_BIND_TO_TEXTURE_RGB_EXT, |
| 378 &value)) { |
| 379 LOG(ERROR) << "glXGetFBConfigAttrib failed."; |
| 380 return false; |
| 381 } |
| 382 if (value == GL_FALSE) |
| 383 continue; |
| 384 if (glXGetFBConfigAttrib( |
| 385 g_display, configs.get()[i], GLX_DOUBLEBUFFER, &value)) { |
| 386 LOG(ERROR) << "glXGetFBConfigAttrib failed."; |
| 387 return false; |
| 388 } |
| 389 // Avoid double buffered config. |
| 390 if (value == GL_TRUE) |
| 391 continue; |
| 392 if (glXGetFBConfigAttrib( |
| 393 g_display, configs.get()[i], GLX_BUFFER_SIZE, &value)) { |
| 394 LOG(ERROR) << "glXGetFBConfigAttrib failed."; |
| 395 return false; |
| 396 } |
| 397 if (value < static_cast<int>(depth)) |
| 398 continue; |
| 399 |
| 400 found = true; |
| 401 break; |
| 402 } |
| 403 |
| 404 if (!found) { |
| 405 LOG(ERROR) << "Failed to find valid FBConfig for pixmap."; |
| 406 return false; |
| 407 } |
| 408 |
| 409 config_ = configs.get()[i]; |
| 410 |
| 411 std::vector<int> attribs; |
| 412 attribs.push_back(GLX_TEXTURE_TARGET_EXT); |
| 413 attribs.push_back(GLX_TEXTURE_2D_EXT); |
| 414 attribs.push_back(GLX_TEXTURE_FORMAT_EXT); |
| 415 if (depth == 32) |
| 416 attribs.push_back(GLX_TEXTURE_FORMAT_RGBA_EXT); |
| 417 else |
| 418 attribs.push_back(GLX_TEXTURE_FORMAT_RGB_EXT); |
| 419 attribs.push_back(0); |
| 420 |
| 421 glx_pixmap_ = glXCreatePixmap( |
| 422 g_display, static_cast<GLXFBConfig>(config_), pixmap_, &attribs.front()); |
| 423 if (!glx_pixmap_) { |
| 424 Destroy(); |
| 425 LOG(ERROR) << "glXCreatePixmap failed."; |
| 426 return false; |
| 427 } |
| 428 |
| 429 return true; |
| 430 } |
| 431 |
| 432 void PixmapGLSurfaceGLX::Destroy() { |
| 433 if (glx_pixmap_) { |
| 434 glXDestroyGLXPixmap(g_display, glx_pixmap_); |
| 435 glx_pixmap_ = 0; |
| 436 } |
| 437 |
| 438 config_ = NULL; |
| 439 } |
| 440 |
| 441 bool PixmapGLSurfaceGLX::IsOffscreen() { |
| 442 return true; |
| 443 } |
| 444 |
| 445 bool PixmapGLSurfaceGLX::SwapBuffers() { |
| 446 NOTREACHED() << "Attempted to call SwapBuffers on a pixmap."; |
| 447 return false; |
| 448 } |
| 449 |
| 450 gfx::Size PixmapGLSurfaceGLX::GetSize() { |
| 451 return size_; |
| 452 } |
| 453 |
| 454 void* PixmapGLSurfaceGLX::GetHandle() { |
| 455 return reinterpret_cast<void*>(glx_pixmap_); |
| 456 } |
| 457 |
| 458 void* PixmapGLSurfaceGLX::GetShareHandle() { |
| 459 return reinterpret_cast<void*>(pixmap_); |
| 460 } |
| 461 |
| 462 void* PixmapGLSurfaceGLX::GetConfig() { |
| 463 return config_; |
| 464 } |
| 465 |
| 466 PixmapGLSurfaceGLX::~PixmapGLSurfaceGLX() { |
| 467 Destroy(); |
| 468 } |
| 469 |
324 } // namespace gfx | 470 } // namespace gfx |
OLD | NEW |