Chromium Code Reviews| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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"); |
| 407 | 408 |
| 408 if (!g_glx_get_msc_rate_oml_supported && g_glx_sgi_video_sync_supported) | 409 if (!g_glx_get_msc_rate_oml_supported && g_glx_sgi_video_sync_supported) |
|
danakj
2016/08/24 22:20:50
Do you want to do this without the command line? S
brianderson
2016/08/24 23:51:19
Sounds like a good idea.
| |
| 409 SGIVideoSyncProviderThreadShim::display_ = gfx::OpenNewXDisplay(); | 410 SGIVideoSyncProviderThreadShim::display_ = gfx::OpenNewXDisplay(); |
| 410 | 411 |
| 411 initialized = true; | 412 initialized = true; |
| 412 return true; | 413 return true; |
| 413 } | 414 } |
| 414 | 415 |
| 415 // static | 416 // static |
| 416 const char* GLSurfaceGLX::GetGLXExtensions() { | 417 const char* GLSurfaceGLX::GetGLXExtensions() { |
| 417 return glXQueryExtensionsString(g_display, 0); | 418 return glXQueryExtensionsString(g_display, 0); |
| 418 } | 419 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 if (event_source) { | 494 if (event_source) { |
| 494 XSelectInput(g_display, window_, ExposureMask); | 495 XSelectInput(g_display, window_, ExposureMask); |
| 495 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | 496 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
| 496 } | 497 } |
| 497 XFlush(g_display); | 498 XFlush(g_display); |
| 498 | 499 |
| 499 GetConfig(); | 500 GetConfig(); |
| 500 DCHECK(config_); | 501 DCHECK(config_); |
| 501 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); | 502 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); |
| 502 | 503 |
| 503 if (g_glx_oml_sync_control_supported) | 504 if (g_glx_oml_sync_control_supported) { |
| 504 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); | 505 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); |
| 505 else if (g_glx_sgi_video_sync_supported) | 506 } else if (g_glx_sgi_video_sync_supported && |
| 507 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 508 switches::kEnableSgiVideoSync)) { | |
| 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. | |
|
piman
2016/08/24 21:04:29
The investigation for bug https://bugs.chromium.or
danakj
2016/08/24 22:20:50
Why not just grab the actual refresh rate here? We
| |
| 516 const base::TimeTicks kDefaultTimebase; | |
| 517 const base::TimeDelta kDefaultInterval = | |
| 518 base::TimeDelta::FromSeconds(1) / 59.9; | |
| 519 vsync_provider_.reset( | |
| 520 new gfx::VSyncProviderStub(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 |