| Index: ui/gl/gl_surface_egl.cc
|
| diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc
|
| index 8c08ff4981c19a04101deca89b10581bd259577a..c34ca0e70e7a25396a82cd9310a90c2ef0630cd6 100644
|
| --- a/ui/gl/gl_surface_egl.cc
|
| +++ b/ui/gl/gl_surface_egl.cc
|
| @@ -54,6 +54,8 @@ using ui::GetLastEGLErrorString;
|
|
|
| namespace gfx {
|
|
|
| +unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0;
|
| +
|
| namespace {
|
|
|
| EGLConfig g_config;
|
| @@ -286,7 +288,9 @@ 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) {
|
| #if defined(OS_ANDROID)
|
| if (window)
|
| ANativeWindow_acquire(window);
|
| @@ -450,12 +454,37 @@ bool NativeViewGLSurfaceEGL::SwapBuffers() {
|
| "width", GetSize().width(),
|
| "height", GetSize().height());
|
|
|
| +#if defined(OS_WIN)
|
| + bool force_no_vsync = false;
|
| + if (swap_interval_ != 0) {
|
| + // This code is a simple way of enforcing that only one surface actually
|
| + // vsyncs 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_) {
|
| + current_swap_generation_++;
|
| + } else {
|
| + force_no_vsync = true;
|
| + eglSwapInterval(GetDisplay(), 0);
|
| + }
|
| +
|
| + swap_generation_ = current_swap_generation_;
|
| + }
|
| +#endif
|
| +
|
| if (!eglSwapBuffers(GetDisplay(), surface_)) {
|
| DVLOG(1) << "eglSwapBuffers failed with error "
|
| << GetLastEGLErrorString();
|
| return false;
|
| }
|
|
|
| +#if defined(OS_WIN)
|
| + if (force_no_vsync) {
|
| + eglSwapInterval(GetDisplay(), swap_interval_);
|
| + }
|
| +#endif
|
| +
|
| return true;
|
| }
|
|
|
| @@ -530,6 +559,10 @@ VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() {
|
| return vsync_provider_.get();
|
| }
|
|
|
| +void NativeViewGLSurfaceEGL::SetSwapInterval(int interval) {
|
| + swap_interval_ = interval;
|
| +}
|
| +
|
| NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
|
| Destroy();
|
| #if defined(OS_ANDROID)
|
|
|