Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Unified Diff: ui/gl/gl_surface_egl.cc

Issue 708483003: Allow Windows to use system Vsync for a single window each swap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment spelling correction Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « ui/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698