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 #include "ui/gl/gl_surface_glx.h" | 5 #include "ui/gl/gl_surface_glx.h" |
6 | 6 |
7 extern "C" { | 7 extern "C" { |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 } | 9 } |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
| 12 #include "base/command_line.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/synchronization/cancellation_flag.h" | 19 #include "base/synchronization/cancellation_flag.h" |
19 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
20 #include "base/threading/non_thread_safe.h" | 21 #include "base/threading/non_thread_safe.h" |
21 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 g_glx_create_context_profile_supported = | 397 g_glx_create_context_profile_supported = |
397 HasGLXExtension("GLX_ARB_create_context_profile"); | 398 HasGLXExtension("GLX_ARB_create_context_profile"); |
398 g_glx_create_context_profile_es2_supported = | 399 g_glx_create_context_profile_es2_supported = |
399 HasGLXExtension("GLX_ARB_create_context_es2_profile"); | 400 HasGLXExtension("GLX_ARB_create_context_es2_profile"); |
400 g_glx_texture_from_pixmap_supported = | 401 g_glx_texture_from_pixmap_supported = |
401 HasGLXExtension("GLX_EXT_texture_from_pixmap"); | 402 HasGLXExtension("GLX_EXT_texture_from_pixmap"); |
402 g_glx_oml_sync_control_supported = | 403 g_glx_oml_sync_control_supported = |
403 HasGLXExtension("GLX_OML_sync_control"); | 404 HasGLXExtension("GLX_OML_sync_control"); |
404 g_glx_get_msc_rate_oml_supported = g_glx_oml_sync_control_supported; | 405 g_glx_get_msc_rate_oml_supported = g_glx_oml_sync_control_supported; |
405 g_glx_sgi_video_sync_supported = | 406 g_glx_sgi_video_sync_supported = |
406 HasGLXExtension("GLX_SGI_video_sync"); | 407 HasGLXExtension("GLX_SGI_video_sync") && |
| 408 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 409 switches::kEnableSgiVideoSync); |
407 | 410 |
408 if (!g_glx_get_msc_rate_oml_supported && g_glx_sgi_video_sync_supported) | 411 if (!g_glx_get_msc_rate_oml_supported && g_glx_sgi_video_sync_supported) |
409 SGIVideoSyncProviderThreadShim::display_ = gfx::OpenNewXDisplay(); | 412 SGIVideoSyncProviderThreadShim::display_ = gfx::OpenNewXDisplay(); |
410 | 413 |
411 initialized = true; | 414 initialized = true; |
412 return true; | 415 return true; |
413 } | 416 } |
414 | 417 |
415 // static | 418 // static |
416 const char* GLSurfaceGLX::GetGLXExtensions() { | 419 const char* GLSurfaceGLX::GetGLXExtensions() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 if (event_source) { | 496 if (event_source) { |
494 XSelectInput(g_display, window_, ExposureMask); | 497 XSelectInput(g_display, window_, ExposureMask); |
495 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | 498 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
496 } | 499 } |
497 XFlush(g_display); | 500 XFlush(g_display); |
498 | 501 |
499 GetConfig(); | 502 GetConfig(); |
500 DCHECK(config_); | 503 DCHECK(config_); |
501 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); | 504 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); |
502 | 505 |
503 if (g_glx_oml_sync_control_supported) | 506 if (g_glx_oml_sync_control_supported) { |
504 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); | 507 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); |
505 else if (g_glx_sgi_video_sync_supported) | 508 } else if (g_glx_sgi_video_sync_supported) { |
506 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(config_, glx_window_)); | 509 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(config_, glx_window_)); |
| 510 } else { |
| 511 // Assume a refresh rate of 59.9 Hz, which will cause us to skip |
| 512 // 1 frame every 10 seconds on a 60Hz monitor, but will prevent us |
| 513 // from blocking the GPU service due to back pressure. This would still |
| 514 // encounter backpressure on a <60Hz monitor, but hopefully that is |
| 515 // not common. |
| 516 const base::TimeTicks kDefaultTimebase; |
| 517 const base::TimeDelta kDefaultInterval = |
| 518 base::TimeDelta::FromSeconds(1) / 59.9; |
| 519 vsync_provider_.reset( |
| 520 new gfx::FixedVSyncProvider(kDefaultTimebase, kDefaultInterval)); |
| 521 } |
507 | 522 |
508 return true; | 523 return true; |
509 } | 524 } |
510 | 525 |
511 void NativeViewGLSurfaceGLX::Destroy() { | 526 void NativeViewGLSurfaceGLX::Destroy() { |
512 vsync_provider_.reset(); | 527 vsync_provider_.reset(); |
513 if (glx_window_) { | 528 if (glx_window_) { |
514 glXDestroyWindow(g_display, glx_window_); | 529 glXDestroyWindow(g_display, glx_window_); |
515 glx_window_ = 0; | 530 glx_window_ = 0; |
516 } | 531 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 if (!config_) | 670 if (!config_) |
656 config_ = GetConfigForWindow(g_display, window_); | 671 config_ = GetConfigForWindow(g_display, window_); |
657 return config_; | 672 return config_; |
658 } | 673 } |
659 | 674 |
660 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { | 675 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { |
661 Destroy(); | 676 Destroy(); |
662 } | 677 } |
663 | 678 |
664 } // namespace gl | 679 } // namespace gl |
OLD | NEW |