| 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> |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 class SGIVideoSyncVSyncProvider | 275 class SGIVideoSyncVSyncProvider |
| 276 : public gfx::VSyncProvider, | 276 : public gfx::VSyncProvider, |
| 277 public base::SupportsWeakPtr<SGIVideoSyncVSyncProvider> { | 277 public base::SupportsWeakPtr<SGIVideoSyncVSyncProvider> { |
| 278 public: | 278 public: |
| 279 explicit SGIVideoSyncVSyncProvider(GLXFBConfig config, GLXWindow glx_window) | 279 explicit SGIVideoSyncVSyncProvider(GLXFBConfig config, GLXWindow glx_window) |
| 280 : vsync_thread_(SGIVideoSyncThread::Create()), | 280 : vsync_thread_(SGIVideoSyncThread::Create()), |
| 281 shim_(new SGIVideoSyncProviderThreadShim(config, glx_window)), | 281 shim_(new SGIVideoSyncProviderThreadShim(config, glx_window)), |
| 282 cancel_vsync_flag_(shim_->cancel_vsync_flag()), | 282 cancel_vsync_flag_(shim_->cancel_vsync_flag()), |
| 283 vsync_lock_(shim_->vsync_lock()) { | 283 vsync_lock_(shim_->vsync_lock()) { |
| 284 vsync_thread_->message_loop()->PostTask( | 284 vsync_thread_->task_runner()->PostTask( |
| 285 FROM_HERE, | 285 FROM_HERE, base::Bind(&SGIVideoSyncProviderThreadShim::Initialize, |
| 286 base::Bind(&SGIVideoSyncProviderThreadShim::Initialize, | 286 base::Unretained(shim_.get()))); |
| 287 base::Unretained(shim_.get()))); | |
| 288 } | 287 } |
| 289 | 288 |
| 290 ~SGIVideoSyncVSyncProvider() override { | 289 ~SGIVideoSyncVSyncProvider() override { |
| 291 { | 290 { |
| 292 base::AutoLock locked(*vsync_lock_); | 291 base::AutoLock locked(*vsync_lock_); |
| 293 cancel_vsync_flag_->Set(); | 292 cancel_vsync_flag_->Set(); |
| 294 } | 293 } |
| 295 | 294 |
| 296 // Hand-off |shim_| to be deleted on the |vsync_thread_|. | 295 // Hand-off |shim_| to be deleted on the |vsync_thread_|. |
| 297 vsync_thread_->message_loop()->DeleteSoon( | 296 vsync_thread_->task_runner()->DeleteSoon(FROM_HERE, shim_.release()); |
| 298 FROM_HERE, | |
| 299 shim_.release()); | |
| 300 } | 297 } |
| 301 | 298 |
| 302 void GetVSyncParameters( | 299 void GetVSyncParameters( |
| 303 const gfx::VSyncProvider::UpdateVSyncCallback& callback) override { | 300 const gfx::VSyncProvider::UpdateVSyncCallback& callback) override { |
| 304 if (kGetVSyncParametersMinSeconds > 0) { | 301 if (kGetVSyncParametersMinSeconds > 0) { |
| 305 base::TimeTicks now = base::TimeTicks::Now(); | 302 base::TimeTicks now = base::TimeTicks::Now(); |
| 306 base::TimeDelta delta = now - last_get_vsync_parameters_time_; | 303 base::TimeDelta delta = now - last_get_vsync_parameters_time_; |
| 307 if (delta.InSeconds() < kGetVSyncParametersMinSeconds) | 304 if (delta.InSeconds() < kGetVSyncParametersMinSeconds) |
| 308 return; | 305 return; |
| 309 last_get_vsync_parameters_time_ = now; | 306 last_get_vsync_parameters_time_ = now; |
| 310 } | 307 } |
| 311 | 308 |
| 312 // Only one outstanding request per surface. | 309 // Only one outstanding request per surface. |
| 313 if (!pending_callback_) { | 310 if (!pending_callback_) { |
| 314 pending_callback_.reset( | 311 pending_callback_.reset( |
| 315 new gfx::VSyncProvider::UpdateVSyncCallback(callback)); | 312 new gfx::VSyncProvider::UpdateVSyncCallback(callback)); |
| 316 vsync_thread_->message_loop()->PostTask( | 313 vsync_thread_->task_runner()->PostTask( |
| 317 FROM_HERE, | 314 FROM_HERE, |
| 318 base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, | 315 base::Bind( |
| 319 base::Unretained(shim_.get()), | 316 &SGIVideoSyncProviderThreadShim::GetVSyncParameters, |
| 320 base::Bind( | 317 base::Unretained(shim_.get()), |
| 321 &SGIVideoSyncVSyncProvider::PendingCallbackRunner, | 318 base::Bind(&SGIVideoSyncVSyncProvider::PendingCallbackRunner, |
| 322 AsWeakPtr()))); | 319 AsWeakPtr()))); |
| 323 } | 320 } |
| 324 } | 321 } |
| 325 | 322 |
| 326 private: | 323 private: |
| 327 void PendingCallbackRunner(const base::TimeTicks timebase, | 324 void PendingCallbackRunner(const base::TimeTicks timebase, |
| 328 const base::TimeDelta interval) { | 325 const base::TimeDelta interval) { |
| 329 DCHECK(pending_callback_); | 326 DCHECK(pending_callback_); |
| 330 pending_callback_->Run(timebase, interval); | 327 pending_callback_->Run(timebase, interval); |
| 331 pending_callback_.reset(); | 328 pending_callback_.reset(); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 if (!config_) | 652 if (!config_) |
| 656 config_ = GetConfigForWindow(g_display, window_); | 653 config_ = GetConfigForWindow(g_display, window_); |
| 657 return config_; | 654 return config_; |
| 658 } | 655 } |
| 659 | 656 |
| 660 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { | 657 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { |
| 661 Destroy(); | 658 Destroy(); |
| 662 } | 659 } |
| 663 | 660 |
| 664 } // namespace gl | 661 } // namespace gl |
| OLD | NEW |