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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 444 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
445 return false; | 445 return false; |
446 } | 446 } |
447 size_ = gfx::Size(attributes.width, attributes.height); | 447 size_ = gfx::Size(attributes.width, attributes.height); |
448 | 448 |
449 if (g_glx_oml_sync_control_supported) | 449 if (g_glx_oml_sync_control_supported) |
450 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_)); | 450 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_)); |
451 else if (g_glx_sgi_video_sync_supported) | 451 else if (g_glx_sgi_video_sync_supported) |
452 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_)); | 452 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_)); |
453 | 453 |
| 454 glx_window_ = glXCreateWindow( |
| 455 g_display, |
| 456 static_cast<GLXFBConfig>(GetConfig()), |
| 457 window_, |
| 458 NULL); |
| 459 if (!glx_window_) { |
| 460 LOG(ERROR) << "glXCreateWindow failed for window " << window_ << "."; |
| 461 return false; |
| 462 } |
| 463 |
454 return true; | 464 return true; |
455 } | 465 } |
456 | 466 |
457 void NativeViewGLSurfaceGLX::Destroy() { | 467 void NativeViewGLSurfaceGLX::Destroy() { |
| 468 if (glx_window_) { |
| 469 glXDestroyWindow(g_display, glx_window_); |
| 470 glx_window_ = 0; |
| 471 } |
458 } | 472 } |
459 | 473 |
460 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) { | 474 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) { |
461 // On Intel drivers, the frame buffer won't be resize until the next swap. If | 475 // On Intel drivers, the frame buffer won't be resize until the next swap. If |
462 // we only do PostSubBuffer, then we're stuck in the old size. Force a swap | 476 // we only do PostSubBuffer, then we're stuck in the old size. Force a swap |
463 // now. | 477 // now. |
464 if (gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer && size_ != size) | 478 if (gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer && size_ != size) |
465 SwapBuffers(); | 479 SwapBuffers(); |
466 size_ = size; | 480 size_ = size; |
467 return true; | 481 return true; |
468 } | 482 } |
469 | 483 |
470 bool NativeViewGLSurfaceGLX::IsOffscreen() { | 484 bool NativeViewGLSurfaceGLX::IsOffscreen() { |
471 return false; | 485 return false; |
472 } | 486 } |
473 | 487 |
474 bool NativeViewGLSurfaceGLX::SwapBuffers() { | 488 bool NativeViewGLSurfaceGLX::SwapBuffers() { |
475 glXSwapBuffers(g_display, window_); | 489 glXSwapBuffers(g_display, glx_window_); |
476 // For latency_tests.cc: | 490 // For latency_tests.cc: |
477 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete"); | 491 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete"); |
478 return true; | 492 return true; |
479 } | 493 } |
480 | 494 |
481 gfx::Size NativeViewGLSurfaceGLX::GetSize() { | 495 gfx::Size NativeViewGLSurfaceGLX::GetSize() { |
482 return size_; | 496 return size_; |
483 } | 497 } |
484 | 498 |
485 void* NativeViewGLSurfaceGLX::GetHandle() { | 499 void* NativeViewGLSurfaceGLX::GetHandle() { |
486 return reinterpret_cast<void*>(window_); | 500 return reinterpret_cast<void*>(glx_window_); |
487 } | 501 } |
488 | 502 |
489 std::string NativeViewGLSurfaceGLX::GetExtensions() { | 503 std::string NativeViewGLSurfaceGLX::GetExtensions() { |
490 std::string extensions = GLSurface::GetExtensions(); | 504 std::string extensions = GLSurface::GetExtensions(); |
491 if (gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer) { | 505 if (gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer) { |
492 extensions += extensions.empty() ? "" : " "; | 506 extensions += extensions.empty() ? "" : " "; |
493 extensions += "GL_CHROMIUM_post_sub_buffer"; | 507 extensions += "GL_CHROMIUM_post_sub_buffer"; |
494 } | 508 } |
495 return extensions; | 509 return extensions; |
496 } | 510 } |
497 | 511 |
498 void* NativeViewGLSurfaceGLX::GetConfig() { | 512 void* NativeViewGLSurfaceGLX::GetConfig() { |
499 if (!config_) { | 513 if (!config_) { |
500 // This code path is expensive, but we only take it when | 514 // This code path is expensive, but we only take it when |
501 // attempting to use GLX_ARB_create_context_robustness, in which | 515 // attempting to use GLX_ARB_create_context_robustness, in which |
502 // case we need a GLXFBConfig for the window in order to create a | 516 // case we need a GLXFBConfig for the window in order to create a |
503 // context for it. | 517 // context for it. |
504 // | 518 // |
505 // TODO(kbr): this is not a reliable code path. On platforms which | 519 // TODO(kbr): this is not a reliable code path. On platforms which |
506 // support it, we should use glXChooseFBConfig in the browser | 520 // support it, we should use glXChooseFBConfig in the browser |
507 // process to choose the FBConfig and from there the X Visual to | 521 // process to choose the FBConfig and from there the X Visual to |
508 // use when creating the window in the first place. Then we can | 522 // use when creating the window in the first place. Then we can |
509 // pass that FBConfig down rather than attempting to reconstitute | 523 // pass that FBConfig down rather than attempting to reconstitute |
510 // it. | 524 // it. |
511 | 525 |
512 XWindowAttributes attributes; | 526 XWindowAttributes attributes; |
513 if (!XGetWindowAttributes( | 527 if (!XGetWindowAttributes( |
514 g_display, | 528 g_display, |
515 reinterpret_cast<GLXDrawable>(GetHandle()), | 529 window_, |
516 &attributes)) { | 530 &attributes)) { |
517 LOG(ERROR) << "XGetWindowAttributes failed for window " << | 531 LOG(ERROR) << "XGetWindowAttributes failed for window " << |
518 reinterpret_cast<GLXDrawable>(GetHandle()) << "."; | 532 window_ << "."; |
519 return NULL; | 533 return NULL; |
520 } | 534 } |
521 | 535 |
522 int visual_id = XVisualIDFromVisual(attributes.visual); | 536 int visual_id = XVisualIDFromVisual(attributes.visual); |
523 | 537 |
524 int num_elements = 0; | 538 int num_elements = 0; |
525 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> configs( | 539 scoped_ptr_malloc<GLXFBConfig, ScopedPtrXFree> configs( |
526 glXGetFBConfigs(g_display, | 540 glXGetFBConfigs(g_display, |
527 DefaultScreen(g_display), | 541 DefaultScreen(g_display), |
528 &num_elements)); | 542 &num_elements)); |
(...skipping 23 matching lines...) Expand all Loading... |
552 config_ = configs.get()[i]; | 566 config_ = configs.get()[i]; |
553 } | 567 } |
554 } | 568 } |
555 | 569 |
556 return config_; | 570 return config_; |
557 } | 571 } |
558 | 572 |
559 bool NativeViewGLSurfaceGLX::PostSubBuffer( | 573 bool NativeViewGLSurfaceGLX::PostSubBuffer( |
560 int x, int y, int width, int height) { | 574 int x, int y, int width, int height) { |
561 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); | 575 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); |
562 glXCopySubBufferMESA(g_display, window_, x, y, width, height); | 576 glXCopySubBufferMESA(g_display, glx_window_, x, y, width, height); |
563 return true; | 577 return true; |
564 } | 578 } |
565 | 579 |
566 void NativeViewGLSurfaceGLX::GetVSyncParameters( | 580 void NativeViewGLSurfaceGLX::GetVSyncParameters( |
567 const UpdateVSyncCallback& callback) { | 581 const UpdateVSyncCallback& callback) { |
568 if (vsync_provider_) | 582 if (vsync_provider_) |
569 vsync_provider_->GetVSyncParameters(callback); | 583 vsync_provider_->GetVSyncParameters(callback); |
570 } | 584 } |
571 | 585 |
572 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() | 586 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 675 |
662 void* PbufferGLSurfaceGLX::GetConfig() { | 676 void* PbufferGLSurfaceGLX::GetConfig() { |
663 return config_; | 677 return config_; |
664 } | 678 } |
665 | 679 |
666 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 680 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
667 Destroy(); | 681 Destroy(); |
668 } | 682 } |
669 | 683 |
670 } // namespace gfx | 684 } // namespace gfx |
OLD | NEW |