| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 bool g_glx_texture_from_pixmap_supported = false; | 49 bool g_glx_texture_from_pixmap_supported = false; |
| 50 bool g_glx_oml_sync_control_supported = false; | 50 bool g_glx_oml_sync_control_supported = false; |
| 51 | 51 |
| 52 // Track support of glXGetMscRateOML separately from GLX_OML_sync_control as a | 52 // Track support of glXGetMscRateOML separately from GLX_OML_sync_control as a |
| 53 // whole since on some platforms (e.g. crosbug.com/34585), glXGetMscRateOML | 53 // whole since on some platforms (e.g. crosbug.com/34585), glXGetMscRateOML |
| 54 // always fails even though GLX_OML_sync_control is reported as being supported. | 54 // always fails even though GLX_OML_sync_control is reported as being supported. |
| 55 bool g_glx_get_msc_rate_oml_supported = false; | 55 bool g_glx_get_msc_rate_oml_supported = false; |
| 56 | 56 |
| 57 bool g_glx_sgi_video_sync_supported = false; | 57 bool g_glx_sgi_video_sync_supported = false; |
| 58 | 58 |
| 59 static const base::TimeDelta kGetVSyncParametersMinPeriod = |
| 60 #if defined(OS_LINUX) |
| 61 // See crbug.com/373489 |
| 62 // On Linux, querying the vsync parameters might burn CPU for up to an |
| 63 // entire vsync, so we only query periodically to reduce CPU usage. |
| 64 // 5 seconds is chosen somewhat abitrarily as a balance between: |
| 65 // a) Drift in the phase of our signal. |
| 66 // b) Potential janks from periodically pegging the CPU. |
| 67 base::TimeDelta::FromSeconds(5); |
| 68 #else |
| 69 base::TimeDelta::FromSeconds(0); |
| 70 #endif |
| 71 |
| 59 class OMLSyncControlVSyncProvider | 72 class OMLSyncControlVSyncProvider |
| 60 : public gfx::SyncControlVSyncProvider { | 73 : public gfx::SyncControlVSyncProvider { |
| 61 public: | 74 public: |
| 62 explicit OMLSyncControlVSyncProvider(gfx::AcceleratedWidget window) | 75 explicit OMLSyncControlVSyncProvider(gfx::AcceleratedWidget window) |
| 63 : SyncControlVSyncProvider(), | 76 : SyncControlVSyncProvider(), |
| 64 window_(window) { | 77 window_(window) { |
| 65 } | 78 } |
| 66 | 79 |
| 67 virtual ~OMLSyncControlVSyncProvider() { } | 80 virtual ~OMLSyncControlVSyncProvider() { } |
| 68 | 81 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 263 } |
| 251 | 264 |
| 252 // Hand-off |shim_| to be deleted on the |vsync_thread_|. | 265 // Hand-off |shim_| to be deleted on the |vsync_thread_|. |
| 253 vsync_thread_->message_loop()->DeleteSoon( | 266 vsync_thread_->message_loop()->DeleteSoon( |
| 254 FROM_HERE, | 267 FROM_HERE, |
| 255 shim_.release()); | 268 shim_.release()); |
| 256 } | 269 } |
| 257 | 270 |
| 258 virtual void GetVSyncParameters( | 271 virtual void GetVSyncParameters( |
| 259 const VSyncProvider::UpdateVSyncCallback& callback) OVERRIDE { | 272 const VSyncProvider::UpdateVSyncCallback& callback) OVERRIDE { |
| 273 if (kGetVSyncParametersMinPeriod > base::TimeDelta()) { |
| 274 base::TimeTicks now = base::TimeTicks::Now(); |
| 275 base::TimeDelta delta = now - last_get_vsync_parameters_time_; |
| 276 if (delta < kGetVSyncParametersMinPeriod) |
| 277 return; |
| 278 last_get_vsync_parameters_time_ = now; |
| 279 } |
| 280 |
| 260 // Only one outstanding request per surface. | 281 // Only one outstanding request per surface. |
| 261 if (!pending_callback_) { | 282 if (!pending_callback_) { |
| 262 pending_callback_.reset( | 283 pending_callback_.reset( |
| 263 new VSyncProvider::UpdateVSyncCallback(callback)); | 284 new VSyncProvider::UpdateVSyncCallback(callback)); |
| 264 vsync_thread_->message_loop()->PostTask( | 285 vsync_thread_->message_loop()->PostTask( |
| 265 FROM_HERE, | 286 FROM_HERE, |
| 266 base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, | 287 base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, |
| 267 base::Unretained(shim_.get()), | 288 base::Unretained(shim_.get()), |
| 268 base::Bind( | 289 base::Bind( |
| 269 &SGIVideoSyncVSyncProvider::PendingCallbackRunner, | 290 &SGIVideoSyncVSyncProvider::PendingCallbackRunner, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 285 scoped_ptr<SGIVideoSyncProviderThreadShim> shim_; | 306 scoped_ptr<SGIVideoSyncProviderThreadShim> shim_; |
| 286 | 307 |
| 287 scoped_ptr<VSyncProvider::UpdateVSyncCallback> pending_callback_; | 308 scoped_ptr<VSyncProvider::UpdateVSyncCallback> pending_callback_; |
| 288 | 309 |
| 289 // Raw pointers to sync primitives owned by the shim_. | 310 // Raw pointers to sync primitives owned by the shim_. |
| 290 // These will only be referenced before we post a task to destroy | 311 // These will only be referenced before we post a task to destroy |
| 291 // the shim_, so they are safe to access. | 312 // the shim_, so they are safe to access. |
| 292 base::CancellationFlag* cancel_vsync_flag_; | 313 base::CancellationFlag* cancel_vsync_flag_; |
| 293 base::Lock* vsync_lock_; | 314 base::Lock* vsync_lock_; |
| 294 | 315 |
| 316 base::TimeTicks last_get_vsync_parameters_time_; |
| 317 |
| 295 DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider); | 318 DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider); |
| 296 }; | 319 }; |
| 297 | 320 |
| 298 SGIVideoSyncThread* SGIVideoSyncThread::g_video_sync_thread = NULL; | 321 SGIVideoSyncThread* SGIVideoSyncThread::g_video_sync_thread = NULL; |
| 299 | 322 |
| 300 // In order to take advantage of GLX_SGI_video_sync, we need a display | 323 // In order to take advantage of GLX_SGI_video_sync, we need a display |
| 301 // for use on a separate thread. We must allocate this before the sandbox | 324 // for use on a separate thread. We must allocate this before the sandbox |
| 302 // goes up (rather than on-demand when we start the thread). | 325 // goes up (rather than on-demand when we start the thread). |
| 303 Display* SGIVideoSyncProviderThreadShim::display_ = NULL; | 326 Display* SGIVideoSyncProviderThreadShim::display_ = NULL; |
| 304 | 327 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 | 689 |
| 667 void* PbufferGLSurfaceGLX::GetConfig() { | 690 void* PbufferGLSurfaceGLX::GetConfig() { |
| 668 return config_; | 691 return config_; |
| 669 } | 692 } |
| 670 | 693 |
| 671 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 694 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
| 672 Destroy(); | 695 Destroy(); |
| 673 } | 696 } |
| 674 | 697 |
| 675 } // namespace gfx | 698 } // namespace gfx |
| OLD | NEW |