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 #if defined(OS_LINUX) | |
Ken Russell (switch to Gerrit)
2014/09/11 18:37:34
Are the OS_LINUX #ifdefs really necessary? This en
brianderson
2014/09/11 18:50:29
I was under the impression the CrOS used this too.
| |
60 // See crbug.com/373489 | |
61 // On Linux, querying the vsync parameters might burn CPU for up to an | |
62 // entire vsync, so we only query periodically to reduce CPU usage. | |
63 // 5 seconds is chosen somewhat abitrarily as a balance between: | |
64 // a) Drift in the phase of our signal. | |
65 // b) Potential janks from periodically pegging the CPU. | |
66 static const base::TimeDelta kGetVSyncParametersMinPeriod = | |
67 base::TimeDelta::FromSeconds(5); | |
68 #endif | |
69 | |
59 class OMLSyncControlVSyncProvider | 70 class OMLSyncControlVSyncProvider |
60 : public gfx::SyncControlVSyncProvider { | 71 : public gfx::SyncControlVSyncProvider { |
61 public: | 72 public: |
62 explicit OMLSyncControlVSyncProvider(gfx::AcceleratedWidget window) | 73 explicit OMLSyncControlVSyncProvider(gfx::AcceleratedWidget window) |
63 : SyncControlVSyncProvider(), | 74 : SyncControlVSyncProvider(), |
64 window_(window) { | 75 window_(window) { |
65 } | 76 } |
66 | 77 |
67 virtual ~OMLSyncControlVSyncProvider() { } | 78 virtual ~OMLSyncControlVSyncProvider() { } |
68 | 79 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 } | 194 } |
184 | 195 |
185 void GetVSyncParameters(const VSyncProvider::UpdateVSyncCallback& callback) { | 196 void GetVSyncParameters(const VSyncProvider::UpdateVSyncCallback& callback) { |
186 base::TimeTicks now; | 197 base::TimeTicks now; |
187 { | 198 { |
188 // Don't allow |window_| destruction while we're probing vsync. | 199 // Don't allow |window_| destruction while we're probing vsync. |
189 base::AutoLock locked(vsync_lock_); | 200 base::AutoLock locked(vsync_lock_); |
190 | 201 |
191 if (!context_ || cancel_vsync_flag_.IsSet()) | 202 if (!context_ || cancel_vsync_flag_.IsSet()) |
192 return; | 203 return; |
193 | |
194 glXMakeCurrent(display_, window_, context_); | 204 glXMakeCurrent(display_, window_, context_); |
195 | 205 |
196 unsigned int retrace_count = 0; | 206 unsigned int retrace_count = 0; |
197 if (glXWaitVideoSyncSGI(1, 0, &retrace_count) != 0) | 207 if (glXWaitVideoSyncSGI(1, 0, &retrace_count) != 0) |
198 return; | 208 return; |
199 | 209 |
200 TRACE_EVENT_INSTANT0("gpu", "vblank", TRACE_EVENT_SCOPE_THREAD); | 210 TRACE_EVENT_INSTANT0("gpu", "vblank", TRACE_EVENT_SCOPE_THREAD); |
201 now = base::TimeTicks::HighResNow(); | 211 now = base::TimeTicks::HighResNow(); |
202 | 212 |
203 glXMakeCurrent(display_, 0, 0); | 213 glXMakeCurrent(display_, 0, 0); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 } | 260 } |
251 | 261 |
252 // Hand-off |shim_| to be deleted on the |vsync_thread_|. | 262 // Hand-off |shim_| to be deleted on the |vsync_thread_|. |
253 vsync_thread_->message_loop()->DeleteSoon( | 263 vsync_thread_->message_loop()->DeleteSoon( |
254 FROM_HERE, | 264 FROM_HERE, |
255 shim_.release()); | 265 shim_.release()); |
256 } | 266 } |
257 | 267 |
258 virtual void GetVSyncParameters( | 268 virtual void GetVSyncParameters( |
259 const VSyncProvider::UpdateVSyncCallback& callback) OVERRIDE { | 269 const VSyncProvider::UpdateVSyncCallback& callback) OVERRIDE { |
270 #if defined(OS_LINUX) | |
Ken Russell (switch to Gerrit)
2014/09/11 18:37:34
Instead of an #ifdef here, could this be written l
brianderson
2014/09/11 18:50:29
Done.
| |
271 base::TimeTicks now = base::TimeTicks::Now(); | |
272 if ((now - last_get_vsync_parameters_time_) < kGetVSyncParametersMinPeriod) | |
273 return; | |
274 last_get_vsync_parameters_time_ = now; | |
275 #endif | |
276 | |
260 // Only one outstanding request per surface. | 277 // Only one outstanding request per surface. |
261 if (!pending_callback_) { | 278 if (!pending_callback_) { |
262 pending_callback_.reset( | 279 pending_callback_.reset( |
263 new VSyncProvider::UpdateVSyncCallback(callback)); | 280 new VSyncProvider::UpdateVSyncCallback(callback)); |
264 vsync_thread_->message_loop()->PostTask( | 281 vsync_thread_->message_loop()->PostTask( |
265 FROM_HERE, | 282 FROM_HERE, |
266 base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, | 283 base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, |
267 base::Unretained(shim_.get()), | 284 base::Unretained(shim_.get()), |
268 base::Bind( | 285 base::Bind( |
269 &SGIVideoSyncVSyncProvider::PendingCallbackRunner, | 286 &SGIVideoSyncVSyncProvider::PendingCallbackRunner, |
(...skipping 15 matching lines...) Expand all Loading... | |
285 scoped_ptr<SGIVideoSyncProviderThreadShim> shim_; | 302 scoped_ptr<SGIVideoSyncProviderThreadShim> shim_; |
286 | 303 |
287 scoped_ptr<VSyncProvider::UpdateVSyncCallback> pending_callback_; | 304 scoped_ptr<VSyncProvider::UpdateVSyncCallback> pending_callback_; |
288 | 305 |
289 // Raw pointers to sync primitives owned by the shim_. | 306 // Raw pointers to sync primitives owned by the shim_. |
290 // These will only be referenced before we post a task to destroy | 307 // These will only be referenced before we post a task to destroy |
291 // the shim_, so they are safe to access. | 308 // the shim_, so they are safe to access. |
292 base::CancellationFlag* cancel_vsync_flag_; | 309 base::CancellationFlag* cancel_vsync_flag_; |
293 base::Lock* vsync_lock_; | 310 base::Lock* vsync_lock_; |
294 | 311 |
312 #if defined(OS_LINUX) | |
313 base::TimeTicks last_get_vsync_parameters_time_; | |
314 #endif | |
315 | |
295 DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider); | 316 DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider); |
296 }; | 317 }; |
297 | 318 |
298 SGIVideoSyncThread* SGIVideoSyncThread::g_video_sync_thread = NULL; | 319 SGIVideoSyncThread* SGIVideoSyncThread::g_video_sync_thread = NULL; |
299 | 320 |
300 // In order to take advantage of GLX_SGI_video_sync, we need a display | 321 // 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 | 322 // 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). | 323 // goes up (rather than on-demand when we start the thread). |
303 Display* SGIVideoSyncProviderThreadShim::display_ = NULL; | 324 Display* SGIVideoSyncProviderThreadShim::display_ = NULL; |
304 | 325 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 | 687 |
667 void* PbufferGLSurfaceGLX::GetConfig() { | 688 void* PbufferGLSurfaceGLX::GetConfig() { |
668 return config_; | 689 return config_; |
669 } | 690 } |
670 | 691 |
671 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 692 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
672 Destroy(); | 693 Destroy(); |
673 } | 694 } |
674 | 695 |
675 } // namespace gfx | 696 } // namespace gfx |
OLD | NEW |