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