Chromium Code Reviews| Index: ui/gl/gl_surface_egl.cc |
| diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc |
| index 19119a9bb0badfc69be76465e8488636a8b4f3d5..e1eafcd5bbcfa20e5a7beec5bd2c17bcce78311e 100644 |
| --- a/ui/gl/gl_surface_egl.cc |
| +++ b/ui/gl/gl_surface_egl.cc |
| @@ -57,6 +57,14 @@ using ui::GetLastEGLErrorString; |
| namespace gfx { |
| +#if defined(OS_WIN) |
| +unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; |
| +unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0; |
| +unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0; |
| + |
| +const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60; |
| +#endif |
| + |
| namespace { |
| EGLConfig g_config; |
| @@ -289,7 +297,10 @@ NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) |
| surface_(NULL), |
| supports_post_sub_buffer_(false), |
| config_(NULL), |
| - size_(1, 1) { |
| + size_(1, 1), |
| + swap_interval_(1), |
| + swap_generation_(0), |
| + vsync_override_(false) { |
| #if defined(OS_ANDROID) |
| if (window) |
| ANativeWindow_acquire(window); |
| @@ -453,6 +464,41 @@ bool NativeViewGLSurfaceEGL::SwapBuffers() { |
| "width", GetSize().width(), |
| "height", GetSize().height()); |
| +#if defined(OS_WIN) |
| + if (swap_interval_ != 0) { |
| + // This code is a simple way of enforcing that we only vsync if one surface |
| + // is swapping per frame. This provides single window cases a stable refresh |
| + // while allowing multi-window cases to not slow down due to multiple syncs |
| + // on a single thread. A better way to fix this problem would be to have |
| + // each surface present on its own thread. |
| + |
| + if (current_swap_generation_ == swap_generation_) { |
| + if (swaps_this_generation_ > 1) |
| + last_multiswap_generation_ = current_swap_generation_; |
| + swaps_this_generation_ = 0; |
| + current_swap_generation_++; |
| + } |
| + |
| + swap_generation_ = current_swap_generation_; |
| + |
| + if (swaps_this_generation_ != 0 || |
| + (current_swap_generation_ - last_multiswap_generation_ < |
| + MULTISWAP_FRAME_VSYNC_THRESHOLD)) { |
| + // Override vsync settings and switch it off |
| + if (!vsync_override_) { |
| + eglSwapInterval(GetDisplay(), 0); |
|
Ken Russell (switch to Gerrit)
2014/11/21 00:05:58
eglSwapInterval applies to the current context. Th
|
| + vsync_override_ = true; |
| + } |
| + } else if (vsync_override_) { |
| + // Only one window swapping, so let the normal vsync setting take over |
| + eglSwapInterval(GetDisplay(), swap_interval_); |
| + vsync_override_ = false; |
| + } |
| + |
| + swaps_this_generation_++; |
| + } |
| +#endif |
| + |
| if (!eglSwapBuffers(GetDisplay(), surface_)) { |
| DVLOG(1) << "eglSwapBuffers failed with error " |
| << GetLastEGLErrorString(); |
| @@ -533,6 +579,10 @@ VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { |
| return vsync_provider_.get(); |
| } |
| +void NativeViewGLSurfaceEGL::SetSwapInterval(int interval) { |
| + swap_interval_ = interval; |
| +} |
| + |
| NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { |
| Destroy(); |
| #if defined(OS_ANDROID) |